c# 入门级Java对比 4 —— 语法,运算符

1. 整数增加了各种无符号类型,从后缀区分如下:

uint、ulong:U\u  u|\ul

2. 字符串类型

a. 常规字符串 “ 我说:\"你好,\\我走了\" “    需转义字符串,转义显示

b. 逐字字符串  @“ 我说:“”你好,\我走了 “” ”  串内字符除引号外全部直接显示,不转义。

3. 比较运算符:浅比较、深比较(字符串、委托)

4. 用户定义的转换类型

a. 隐式转换:

public static implicit operator TargetType (SourceType value)
{
    return TargetTypeValue;
}
b. 显示转换:

public static explicit operator int (LimitedInt value) 
{
    return li.TheValue;
}
c. 二者区别

1) 定义关键字区别 implicit、explicit

2) 使用区别

LimitedInt limitedInt = 5;
int value = limitedInt;// 隐式转换

LimitedInt limitedInt = 5;
int value = (int)limitedInt;// 显示转换

5. 支持运算符重载:

+、-、!、~、++、--、true、false;

 *、/、%、&、|、^、<<、>>、==、!=、>、<、>=、<=;

public static Second operator + (Second second, int up) {
    Second result = second;
    result.age += up - 2;
    return result;
}

6. typeOf运算符,类似反射概念,不可被重载。

7. switch, case 没有跳转语句不允许包含任何语句,如果需要,可跳转到其他case:goto case 2;

8. using语句结合IDisposed接口,实现资源自动处置操作。

using (ResourceType Identifier = Expression, <span style="font-family: Arial, Helvetica, sans-serif;">Identifier2 = Expression</span>)
{
   ...
}
ResourceType Identifier = Expression;// 在语句外创建,释放后可能仍然使用,不推荐此方式
using (Identifier)
{
   ...
}

9. 待补充:

checked、unchecked、yield、foreach、try\throw\finally


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值