日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問(wèn) 生活随笔!

生活随笔

當(dāng)前位置: 首頁(yè) > 编程语言 > C# >内容正文

C#

c# 赋值运算符_C#程序演示赋值运算符的示例

發(fā)布時(shí)間:2025/3/11 C# 38 豆豆
生活随笔 收集整理的這篇文章主要介紹了 c# 赋值运算符_C#程序演示赋值运算符的示例 小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

c# 賦值運(yùn)算符

Assignment operators (Assignment (=) and compound assignments (+=, -+, *=, /=, %=)) are used to assign the value or an expression's result to the left side variable, following are the set of assignment operators,

賦值運(yùn)算符(Assignment( = )和復(fù)合賦值( + = , -+ , * = , / = , %= ))用于將值或表達(dá)式的結(jié)果賦給左側(cè)變量,以下是賦??值運(yùn)算符集,

  • "=" – it is used to assign value or an expression's result to the left side variable

    “ =” –用于將值或表達(dá)式的結(jié)果分配給左側(cè)變量

  • "+=" – it is used to add second operand to the existing operand's value and assigns it back (a+=b is equal to a=a+b)

    “ + =” –用于將第二個(gè)操作數(shù)添加到現(xiàn)有操作數(shù)的值并將其賦值回去(a + = b等于a = a + b)

  • "-=" – it is used to subtract second operand from the existing operand's value and assigns it back (a-=b is equal to a=a-b)

    “-=” –用于從現(xiàn)有操作數(shù)的值中減去第二個(gè)操作數(shù)并將其賦值回去(a- = b等于a = ab)

  • "/=" – it is used to divide second operand from the existing operand's value and assigns it back (a/=b is equal to a=a+b)

    “ / =” –用于將第二個(gè)操作數(shù)與現(xiàn)有操作數(shù)的值相除并將其賦值回去(a / = b等于a = a + b)

  • "*=" – it is used to multiply second operand with the existing operand's value and assigns it back (a*=b is equal to a=a*b)

    “ * =” –用于將第二個(gè)操作數(shù)與現(xiàn)有操作數(shù)的值相乘并賦值回去(a * = b等于a = a * b)

  • "%=" – it is used to get the remainder by dividing second operand with the existing operand's value and assigns it back (a%=b is equal to a=a%b)

    “%=” –用于通過(guò)將第二個(gè)操作數(shù)除以現(xiàn)有操作數(shù)的值來(lái)獲得余數(shù),并將其賦值回去(a%= b等于a = a%b)

  • Example:

    例:

    Input:int a = 10;int b = 3;//operations & outputsa = 100; //value of a will be 100a += b; //value of a will be 103a -= b; //value of a will be 100a *= b; //value of a will be 300a /= b; //value of a will be 100a %= b; //value of a will be 1

    C# code to demonstrate example of assignment operators

    C#代碼演示賦值運(yùn)算符的示例

    // C# program to demonstrate example of // assignment operators using System; using System.IO; using System.Text;namespace IncludeHelp {class Test{// Main Method static void Main(string[] args){int a = 10;int b = 3;Console.WriteLine("a: {0}", a);a = 100; //assigmentConsole.WriteLine("a: {0}", a);a += b;Console.WriteLine("a: {0}", a);a -= b;Console.WriteLine("a: {0}", a);a *= b;Console.WriteLine("a: {0}", a);a /= b;Console.WriteLine("a: {0}", a);a %= b;Console.WriteLine("a: {0}", a);//hit ENTER to exit the programConsole.ReadLine();}} }

    Output

    輸出量

    a: 10 a: 100 a: 103 a: 100 a: 300 a: 100 a: 1

    翻譯自: https://www.includehelp.com/dot-net/assignment-operators-example-in-c-sharp.aspx

    c# 賦值運(yùn)算符

    總結(jié)

    以上是生活随笔為你收集整理的c# 赋值运算符_C#程序演示赋值运算符的示例的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。

    如果覺(jué)得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。