All articles| All Pictures| All Softwares| All Video| Go home page| Write articles| Upload pictures

Reading number is top 10 articles
在ASP.net中从SQL数据库保存取出图片(可用于上传图片)
利用asp.net输出RSS_[Asp.Net教程]
配置文件中PHP最常用四个ini函数_[PHP教程]
实例研究PHP函数isset和empty的区别_php资料_编程技术
.NET字符串的特点,正则表达式在其中如何运用_.net资料_编程技术
PHP语言中的经典应用技巧_[PHP教程]
点击gridview的删除按钮弹出确认消息框_[Asp.Net教程]
斜体样式的导航条_JavaScript技术_编程技术
在Linux下开发.Net程序的环境搭建_[Asp.Net教程]
使用C#开发SmartPhone程序入门_.net资料_编程技术
Reading number is top 10 pictures
这才叫绝色美女1
Ashlynn Brooke a group sexy photo1
再发两张抽象画
Sell the barbecue as says father du breul3
The real super beauty6
Terrorist smile the largest human history an explosion2
色狗系列
Go to the national museum1
Athena chu perspective cheongsam shine with New York
The other a successor of sora aoi
Download software ranking
Tram sex maniac 2 (H) rar bag9
Tram sex maniac 2 (H) rar bag6
C#编程思想
Ashlynn Video4
Prostitutes diary
Professional killers2 for Android
Eclipse 4.2.2 For Win64
传奇私服架设教程-chm
超级战舰
Kung fu panda - the secret of the teacher
qq published in(发表于) 2014/7/11 9:21:40 Edit(编辑)
C#教程:C#中的赋值运算符

C#教程:C#中的赋值运算符

C#教程:C#中的赋值运算符

赋值运算符

赋值运算符有=、+=、−=、*=、/=、%=、&=、|=、^=、<<=、>>=、??等。

赋值操作符的左操作数必须是一个变量、属性访问器或索引访问器的表达式,赋值结果将一个新的数值存放在左操作数所在的内存空间中。

在C# 中,可以对变量进行连续赋值,这时赋值操作符是右关联的,这意味着从右向左操作符被分组,如x=y=z等价于x=(y=z)。

如果操作符两侧的操作数类型不一致,则应先进行类型转换。

本教程来自http://www.isstudy.com

给变量赋值的表达式称为赋值表达式,赋值表达式的值用于给变量赋值。

赋值操作符的运算对象、运算法则及运算结果如表1所示。



表1 赋值操作符的运算规则

在C# 中,所有赋值和自反赋值操作符的优先级都是一样的,比所有其他操作符的优先级都低,是优先级最低的操作符。

示例

赋值和自反赋值操作符的优先级

下面的示例代码演示了赋值和自反赋值操作符的优先级。

using System;

class TestClass

{

static void Main()

{

int i;

double d;

i = 5;

d=i;

d +=i;

Console.WriteLine("i 是 {0},d 是 {1}",i, d);

}

}

输出结果:

i 是 5, d 是 10


d +=i;等于d=d+i; 以下 -= 、 *= 、 /= 、 %= 、&=、|=、^=、 <<= 、>>=与之相同。

“??”是一种比较特殊的赋值运算符,含义是如果“??”运算符的左操作数非空,该运算符将返回左操作数,否则返回右操作数。

示例

??”操作符的使用

下面的示例代码演示了如何对y用“??”运算符进行赋值。

using System;

class TestClass

{

static void Main()

{

int? x = null;//给可以为null的类型赋值

// y = x,如果 x 是 null, 则 y = -1.

int y = x ?? -1;

Console.WriteLine("y是{0}",y);

}

}

输出结果:

y是-1


完整程序代码如下:

★★★★★主程序文件完整程序代码★★★★★

using System;

using System.Collections.Generic;

using System.Text;

namespace _2_05

{

class Program

{

static void Main(string[] args)

{

int i;

double d;

i = 5;

d = i;

d += i;

Console.WriteLine("i 是 {0},d 是 {1}", i, d);

}

}

}


完整程序代码如下:

本教程来自http://www.isstudy.com

★★★★★主程序文件完整程序代码★★★★★

using System;

using System.Collections.Generic;

using System.Text;

namespace _2_06

{

class Program

{

static void Main(string[] args)

{

int? x = null;//给可以为null的类型赋值

// y = x,如果 x 是 null, 则 y = -1.

int y = x ?? -1;

Console.WriteLine("y是{0}",y);

}

}

}




添加到del.icio.us 添加到新浪ViVi 添加到百度搜藏 添加到POCO网摘 添加到天天网摘365Key 添加到和讯网摘 添加到天极网摘 添加到黑米书签 添加到QQ书签 添加到雅虎收藏 添加到奇客发现 diigo it 添加到饭否 添加到飞豆订阅 添加到抓虾收藏 添加到鲜果订阅 digg it 貼到funP 添加到有道阅读 Live Favorites 添加到Newsvine 打印本页 用Email发送本页 在Facebook上分享


Disclaimer Privacy Policy About us Site Map

If you have any requirements, please contact webmaster。(如果有什么要求,请联系站长)
Copyright ©2011-
uuhomepage.com, Inc. All rights reserved.