c# 赋值运算符_C#程序演示赋值运算符的示例
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)
“%=” –用于通過將第二個(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 1C# 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)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: JavaScript中的嵌套事件处理(在
- 下一篇: java math 类_Java Mat