c# 新的实用但容易忘记的方法

 1. public static string Join( string separator, string[] value)
  在指定 String 数组的每个元素之间串联指定的分隔符 String,从而产生单个串联的字符串。

  例如,如果 separator 为“,”且 value 的元素为“apple”、“orange”、“grape”和“pear”,

  则 Join(separator,  value) 返回“apple, orange, grape, pear”。

  如果 separatornullNothingnullptrnull 引用(在 Visual Basic 中为 Nothing,则改用空字符串 (Empty)。

2.?? 运算符

  如果 ?? 运算符的左操作数非 null,该运算符将返回左操作数,否则返回右操作数。

  // ?? operator example. int? x = null;

  // y = x, unless x is null, in which case y = -1. int y = x ?? -1;

3. String.IsNullOrEmpty 方法
 返回值类型: System.Boolean

 如果 value 参数为 nullNothingnullptrnull 引用(在 Visual Basic 中为 Nothing 或空字符串 (""),

 则为 true;否则为 false

4.String.Format 方法

  将指定的 String 中的格式项替换为指定的 Object 实例的值的文本等效项

  s = String.Format( "(d) Short date: . . . . . . . {0:d}/n",DateTime.Now);

  输出:

 (d) Short date: . . . . . . . 6/26/2004

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值