• Mark Forums Read
  • Today's Posts
  • View Site Leaders
  • What's New?
  • Advanced Search
[RESOLVED] (newbie question) "Use compound assignment" in a simple program by clicking the link above. You may have to before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below. New Member --> The error message says the error occurs on Line 12, where there is the statement n = n/2. This seems to be a fatal error, as the program neither compiles nor runs. Any ideas?

Paul King . Reason: Complete code
New Member --> I just compiled it again, and I am getting a different error:
I didn't change anything. When I set up the project, I didn't like saving the project to C: drive, so I chose a location on another drive. There was also a pop-up I got which said that the exe file that was "in my debug profile" doesn't exist -- which was a strange error. Where is this debug profile, and how can I change it?

Paul .
New Member --> I didn't change anything. When I set up the project, I didn't like saving the project to C: drive, so I chose a location on another drive. There was also a pop-up I got which said that the exe file that was "in my debug profile" doesn't exist -- which was a strange error. Where is this debug profile, and how can I change it?

Paul It looks like VB made sub Main() my startup object in the debug configuration. I changed it to "Form1". This was under the "Debug|ProgName debug Properties" menu item. A tab of debug properties comes up,and you need to choose the "Application" tab, and change the setting for Startup Object near the bottom of that form.

|
| |
| | | | | | |

| [RESOLVED] (newbie question) "Use compound assignment" in a simple program Posting Permissions post new threads post replies post attachments edit your posts is are code is code is





 alt=

Advertiser Disclosure: Some of the products that appear on this site are from companies from which TechnologyAdvice receives compensation. This compensation may impact how and where products appear on this site including, for example, the order in which they appear. TechnologyAdvice does not include all companies or all types of products available in the marketplace.

ReSharper 2024.1 Help

Code inspection: use compound assignment.

Category : Language Usage Opportunities

ID : ConvertToNullCoalescingCompoundAssignment

EditorConfig : resharper_convert_to_null_coalescing_compound_assignment_highlighting

Default severity : Suggestion

Language : C#

Requires SWA : No

This inspection suggests using a compound assignment expression to make the code more concise and easier to read. Compound assignments are shorthand ways of combining arithmetic, boolean, bitwise, and other binary operators with the assignment operator = . They can help reduce repetitive code and make the intent of the code clearer.

The most commonly used compound assignment expression is probably the addition assignment ( x += y ), but there are other compound assignments that can come in handy. Here are some examples:

  • Trending Categories

Data Structure

  • Selected Reading
  • UPSC IAS Exams Notes
  • Developer's Best Practices
  • Questions and Answers
  • Effective Resume Writing
  • HR Interview Questions
  • Computer Glossary

Compound assignment operators in C#

A compound assignment operator has a shorter syntax to assign the result. The operation is performed on the two operands before the result is assigned to the first operand.

The following are the compound assignment operators in C#.

Sr.NoOperator & Operator Name
1
Addition Assignment
2
Subtraction Assignment
3
Multiplication Assignment
4
Division Assignment
5
Modulo Assignment
6
Bitwise AND Assignment
7
Bitwise OR Assignment
8
Bitwise XOR Assignment
9
Left Shift Assignment
10
Right Shift Assignment
11
Lambda Operator

Let us see an example to learn how to work with compound assignment operators in C#.

 Live Demo

Samual Sam

  • Related Articles
  • Compound Assignment Operators in C++
  • Compound assignment operators in Java\n
  • Perl Assignment Operators
  • Assignment operators in Dart Programming
  • Compound operators in Arduino
  • What is the difference between = and: = assignment operators?
  • Passing the Assignment in C++
  • Airplane Seat Assignment Probability in C++
  • Copy constructor vs assignment operator in C++
  • Unary operators in C/C++
  • Ternary Operators in C/C++
  • # and ## Operators in C ?
  • Operators Precedence in C++
  • Unary operators in C++
  • Conversion Operators in C++

Kickstart Your Career

Get certified by completing the course

Navigation Menu

Search code, repositories, users, issues, pull requests..., provide feedback.

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly.

To see all available qualifiers, see our documentation .

  • Notifications You must be signed in to change notification settings

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement . We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

IDE0074 'Use compound assignment' should not be offered for pre-8.0 language versions #44793

@CyrusNajmabadi

jnm2 commented Jun 2, 2020

: 16.6.0, 16.6.1, 16.7-p1

C { void M(object p) { // ℹ IDE0074 Use compound assignment // ↓↓ _ = p ?? (p = new object()); } }

🛠 Use compound assignment:

C { void M(object p) { // ❌ CS8370 Feature 'coalescing assignment' is not available in C# 7.3. Please use // language version 8.0 or greater. // ↓↓↓ _ = (p ??= new object()); } }

Repros with either of these:

Sdk="Microsoft.NET.Sdk"> <PropertyGroup> <TargetFramework>netcoreapp3.1</TargetFramework> <LangVersion>7.3</LangVersion> </PropertyGroup> </Project> Sdk="Microsoft.NET.Sdk"> <PropertyGroup> <TargetFramework>net48</TargetFramework> </PropertyGroup> </Project>
  • 👍 2 reactions

@CyrusNajmabadi

CyrusNajmabadi commented Jun 2, 2020

did you add support for this?

Sorry, something went wrong.

@333fred

333fred commented Jun 2, 2020

No, I'm not sure who added this refactoring.

ok. i'll find out. thanks!

CyrusNajmabadi commented Jun 2, 2020 • edited Loading

N/M. This is a different feature. I will fix :)

@ghost

sharwell commented Jul 22, 2020

Can you set the milestone for this to match the one in ?

@sharwell

HugCoder commented Dec 7, 2020 • edited Loading

Sorry if reopening. This issue is still present in 16.8.2. The merged "Only offer 'Use expression' in C#8 and above. " doesn't seem to cover the issue of assignment (IDE0054). I'm targetting .NET 4.6.2 if that matters.

Thanks for all you work!

jnm2 commented Dec 8, 2020 • edited Loading

Perhaps this is fixed by the fix for which will be in 16.9.P2?

HugCoder commented Dec 8, 2020

I did find that issue as well, but it wasn't targetting the null operator mentioned here. It certainly could be addressing the issue of the null-coalescing assignment operator as well but I'm afraid it's above my league in this topic to say if it does. I'm not sure how specific the fixes for these kind of issues are and just wanted to make sure it wasn't overlooked and viewed as solved in VS 16.8.

This issue is about IDE0074 incorrectly recommending to replace for langversion < 8 and was fixed in 16.7.P4. The same concern can't apply to other kinds of compound assignment because they are legal in langversion < 8.

is about IDE0054 firing incorrectly in a C# 9 target-typed new initializer and will be fixed in 16.9.P2.

Is your concern that IDE0054 fired incorrectly in a C# 9 target-typed new initializer, specifically recommending ?
Or is there a new element involved such as expressions, or am I misunderstanding? If I am, it would really help me to see a sample line of code.

jnm2 commented Dec 8, 2020

Incidentally, 16.9.P2 just dropped in the preview channel, so we'll be able to test your concern about whether it was fixed for sure in that pull request in a minute or two :D

No squiggle, so it looks like was completely fixed in 16.9.P2:

  • 👍 1 reaction

HugCoder commented Dec 8, 2020 • edited Loading

Thanks for looking at this. It looks like it might be fixed now, from your test, but just to be clear I'm talking about e.g.
a = a ?? "hello";
wanting through IDE0054 to refactor it to:
a ??= "hello";

This is in VS 16.8.2 though, targetting .NET 4.6.1 (C# 7.3). Might be fixed now, so no big issue for me. Thanks to all who work on Roslyn :)

That's very close to the example I have at the top of this issue which IIRC didn't repro for 16.8.2 for me earlier today with in my test csproj.

In any case, 16.8.3 doesn't repro this which matches your screenshot:

C { void M(string a) { a = a ?? "hello"; } } Sdk="Microsoft.NET.Sdk"> <PropertyGroup> <TargetFramework>net461</TargetFramework> </PropertyGroup> </Project>

This makes me think there's something going on with your project that can't be seen from your description so far. E.g. are you multitargeting?

Successfully merging a pull request may close this issue.

@sharwell

  • Stack Overflow for Teams Where developers & technologists share private knowledge with coworkers
  • Advertising & Talent Reach devs & technologists worldwide about your product, service or employer brand
  • OverflowAI GenAI features for Teams
  • OverflowAPI Train & fine-tune LLMs
  • Labs The future of collective knowledge sharing
  • About the company Visit the blog

Collectives™ on Stack Overflow

Find centralized, trusted content and collaborate around the technologies you use most.

Q&A for work

Connect and share knowledge within a single location that is structured and easy to search.

Get early access and see previews of new features.

What does "Convert into compound assignment" mean?

What does Convert into compound assignment for p.y mean in the context in this image?

enter image description here

The code seems to work just fine.

Wondering why that suggesting by the IDE?

  • unity-game-engine

Patrioticcow's user avatar

See Compound Assignment .

For a binary operator op, a compound assignment expression of the form:

is equivalent to

It simply makes your code more compact and (arguably) more readable.

Luke Vo's user avatar

  • 1 Damnit, I'm so stupid, I thought it meant something needed to be done Unity way, and not a general programming thing. –  Patrioticcow Commented Mar 31, 2023 at 3:43
  • @Patrioticcow No worry, we learn new simple things everyday ;) –  Luke Vo Commented Mar 31, 2023 at 3:50
  • @Patrioticcow for the next time - couldn't you just have tried? Simply click on that and see what it does to the code ^^ –  derHugo Commented Mar 31, 2023 at 6:44

Your Answer

Reminder: Answers generated by artificial intelligence tools are not allowed on Stack Overflow. Learn more

Sign up or log in

Post as a guest.

Required, but never shown

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy .

Not the answer you're looking for? Browse other questions tagged c# unity-game-engine or ask your own question .

  • The Overflow Blog
  • This developer tool is 40 years old: can it be improved?
  • Unpacking the 2024 Developer Survey results
  • Featured on Meta
  • We've made changes to our Terms of Service & Privacy Policy - July 2024
  • Introducing an accessibility dashboard and some upcoming changes to display...
  • Tag hover experiment wrap-up and next steps

Hot Network Questions

  • Closed form of an integral using Mathematica or otherwise
  • What does "you must keep" mean in "you must keep my covenant", Genesis 17:9?
  • "Seagulls are gulling away."
  • What happens if your child sells your car?
  • When/why did software only engines overtake custom hardware?
  • Adding another forest or tree to the existing one
  • What does "No camping 10-21" mean?
  • Why some bech32 bitcoin addresses contain a structure with a large number of "q"?
  • Reference for the proof that Möbius transformations extend to isometries of hyperbolic 3-space
  • Make a GCSE student's error work
  • Excel - creating a chart using column data as x axis labels - how to set date intervals to yearly, rather than daily?
  • How to make footnotes have a single margin
  • A finance broker made me the primary instead of a co-signer
  • Challenges to complete apple ID account to download Apps when in an unsupported country
  • Why is “water takes the steepest path downhill” a common approximation?
  • Possible downsides of not dealing with the souls of the dead
  • Backfill civicrm_mailing unknown error when upgrading to 5.76.0
  • Why did the Black Order leave Heimdall alive?
  • Four Year Old Pushing and Positive Discipline Techniques
  • Can right shift by n-bits operation be implemented using hardware multiplier just like left shift?
  • English equilvant to this hindi proverb "A washerman's dog belongs neither at home nor at the riverbank."?
  • Solar System Replacement?
  • Abrupt increase of evaluation time of MatrixExp
  • English equivalent to the famous Hindi proverb "the marriage sweetmeat: those who eat it regret, and those who don't eat it also regret"?

ide0054 use compound assignment

このブラウザーはサポートされなくなりました。

Microsoft Edge にアップグレードすると、最新の機能、セキュリティ更新プログラム、およびテクニカル サポートを利用できます。

複合代入を使用する (IDE0054 および IDE0074)

この記事では、 IDE0054 と IDE0074 という 2 つの関連するルールについて説明します。

プロパティ
IDE0054
複合代入を使用する
スタイル
言語規則 (式レベル基本設定)
C# および Visual Basic
プロパティ
IDE0074
結合複合代入を使用する
スタイル
言語規則 (式レベル基本設定)
C# および Visual Basic

これらの規則は、 複合代入 の使用に関するものです。 結合複合代入には IDE0074 が、その他の複合代入には IDE0054 がレポートされます。

オプション値によって、複合代入が必要かどうかを指定します。

オプションの構成の詳細については、「 オプションの書式 」を参照してください。

dotnet_style_prefer_compound_assignment

プロパティ 説明
dotnet_style_prefer_compound_assignment
複合代入式を優先します
複合代入式を優先しません

単一の違反だけを抑制する場合は、ソース ファイルにプリプロセッサ ディレクティブを追加して無効にしてから、規則を再度有効にします。

ファイル、フォルダー、またはプロジェクトのルールを無効にするには、 構成ファイル でその重要度を none に設定します。

すべてのコード スタイル規則を無効にするには、 構成ファイル でカテゴリ Style の重要度を none に設定します。

詳細については、「 コード分析の警告を抑制する方法 」を参照してください。

  • コード スタイルの言語規則
  • コード スタイルの規則のリファレンス

以下は間もなく提供いたします。2024 年を通じて、コンテンツのフィードバック メカニズムとして GitHub の issue を段階的に廃止し、新しいフィードバック システムに置き換えます。 詳細については、「 https://aka.ms/ContentUserFeedback 」を参照してください。

フィードバックの送信と表示

COMMENTS

  1. Use compound assignment (IDE0054 and IDE0074)

    These rules concern the use of compound assignment. IDE0074 is reported for coalesce compound assignments and IDE0054 is reported for other compound assignments. Options. The option value specifies whether or not compound assignments are desired. For information about configuring options, see Option format. dotnet_style_prefer_compound_assignment

  2. c#

    You _certainly wouldn't do. myFactory.GetNextObject().MyProperty = myFactory.GetNextObject().MyProperty + 5; You could again use a temp variable, but the compound assignment operator is obviously more succinct. Granted, these are edge cases, but it's not a bad habit to get into. answered Aug 17, 2020 at 21:50.

  3. docs/docs/fundamentals/code-analysis/style-rules/ide0054 ...

    Use compound assignment (IDE0054 and IDE0074) This article describes two related rules, IDE0054 and IDE0074. Property Value; Rule ID: IDE0054: Title: Use compound assignment: Category: Style: Subcategory: Language rules (expression-level preferences) Applicable languages: C# and Visual Basic: Options: dotnet_style_prefer_compound_assignment ...

  4. IDE0054 "Use compound assignment" false positive in object ...

    There is an IDE0054 "Use compound assignment" hint for level = level - 1, but this doesn't make sense in an object initializer. The text was updated successfully, but these errors were encountered: All reactions. ...

  5. Code-style rules overview

    Use expression body for lambdas: csharp_style_expression_bodied_lambdas: IDE0054: Use compound assignment: dotnet_style_prefer_compound_assignment: IDE0055: Fix formatting (Too many to list here. See .NET formatting options and C# formatting options.) IDE0056: Use index operator: csharp_style_prefer_index_operator: IDE0057: Use range operator

  6. IDE0054 Use compound assignment

    Fix IDE0054 for increment/decrement when dealing with user-defined operators #70653 Merged jaredpar added Area-IDE and removed Area-Compilers labels Nov 1, 2023

  7. Assignment operators

    Compound assignment. For a binary operator op, a compound assignment expression of the form. x op= y is equivalent to. x = x op y ... Use compound assignment (style rules IDE0054 and IDE0074) Collaborate with us on GitHub. The source for this content can be found on GitHub, where you can also create and review issues and pull requests. ...

  8. VS 2019 [RESOLVED] (newbie question) "Use compound assignment" in a

    Re: (newbie question) "Use compound assignment" in a simple program It both compiles and runs for me. The issue about compound assignment is just a suggestion by Visual Studio - you can rewrite that statement as "n /= 2", but your version is still correct.

  9. IDE0054 "Use compound assignment" false positive in target ...

    There should be no IDE0054 diagnostics here: class C { public string P { get; set; } public C Clone() { // ↓ IDE0054 Use compound assignment return n... Version Used: 16.8.0 and 16.9-p1 #33382 came back but only when using target-typed new.

  10. Code inspection: Use compound assignment

    Compound assignments are shorthand ways of combining arithmetic, boolean, bitwise, and other binary operators with the assignment operator =. They can help reduce repetitive code and make the intent of the code clearer. The most commonly used compound assignment expression is probably the addition assignment ( x += y ), but there are other ...

  11. Code-style language and unnecessary code rules

    Use compound assignment (IDE0054, IDE0074) Remove unnecessary expression value (IDE0058) Remove unnecessary value assignment (IDE0059) Use 'System.HashCode.Combine' (IDE0070) Simplify interpolation (IDE0071) Simplify conditional expression (IDE0075) Convert typeof to nameof (IDE0082) Remove unnecessary equality operator (IDE0100)

  12. Compound assignment operators in C#

    Compound assignment operators in C - A compound assignment operator has a shorter syntax to assign the result. The operation is performed on the two operands before the result is assigned to the first operand.The following are the compound assignment operators in C#.Sr.NoOperator & Operator Name1+=Addition Assignment2-=Subtraction Assi

  13. IDE0054 Use compound assignment is offered for "with ...

    IDE0054 Use compound assignment is offered for "with" initialization expression #50133. Closed JakenVeina opened this issue Dec 26, 2020 · 1 comment Closed ... Suggestion IDE0054 should not be offered on line 8, since the result is not actually valid syntax. Actual Behavior:

  14. dotnet-docs/docs/fundamentals/code-analysis/style-rules/ide0054-ide0074

    IDE0054: Use compound assignment IDE0074: Use coalesce compound assignment: Category: Style: Subcategory: Language rules (expression-level preferences) Applicable languages: C# and Visual Basic: Overview. This style rule concerns with the use of compound assignments. The option value specifies whether or not they are desired.

  15. c

    Advantage of using compound assignment. There is a disadvantage too. Consider the effect of types. long long exp1 = 20; int b=INT_MAX; // All additions use `long long` math. exp1 = exp1 + 10 + b; 10 + b addition below will use int math and overflow ( undefined behavior) exp1 += 10 + b; // UB.

  16. IDE0074 'Use compound assignment' should not be offered for ...

    Sorry if reopening. This issue is still present in 16.8.2. The merged "Only offer 'Use coalesce expression' in C#8 and above. #44798" doesn't seem to cover the issue of compound assignment (IDE0054). I'm targetting .NET 4.6.2 if that matters. Thanks for all you work!

  17. 使用复合赋值(IDE0054 和 IDE0074)

    如果只想抑制单个冲突,请将预处理器指令添加到源文件以禁用该规则,然后重新启用该规则。. 若要对文件、文件夹或项目禁用该规则,请在 配置文件 中将其严重性设置为 none 。. dotnet_diagnostic.IDE0074.severity = none. 若要禁用所有代码样式规则,请在 配置文件 ...

  18. What does "Convert into compound assignment" mean?

    See Compound Assignment. For a binary operator op, a compound assignment expression of the form: x += y. is equivalent to. x = x + y. It simply makes your code more compact and (arguably) more readable. answered Mar 31, 2023 at 3:32. Luke Vo.

  19. 複合代入を使用する (IDE0054 および IDE0074)

    概要. これらの規則は、複合代入の使用に関するものです。 結合複合代入には ide0074 が、その他の複合代入には ide0054 がレポートされます。. オプション. オプション値によって、複合代入が必要かどうかを指定します。