看到Console.WriteLine($"string")写法,一时间不理解$的用途
Null-Conditional Operator
public static string Truncata(string value, int length)
{
string result = value;
if (value != null)
{
result = value.Substring(, Math.Min(value.Length, length));
}
return result;
}
public static string Truncata(string value, int length)
{
return value?.Substring(, Math.Min(value.Length, length));
}
Auto-Property Initializers
public static string name{get;set;}
static void Main(string[] args)
{
name="test";
}
public static string name{get;set;} ="test";
void ThrowArgumentNullExceptionUsingNameof(string parame1)
{
throw new ArgumentNullException(nameof(parame1));
}
Primary Constructors
public static string name{get;private set;}
public static string name {get;}="test";//不用带上 private set;
Expression Bodied Functions and Properties
public class class1
{
public string First { get; set; }
public string Second { get; set; }
public override string ToString()
{
return string.Format("{0},{1}", First, Second);
}
}
public override string ToString() => string.Format("{0},{1}", First, Second);
$
static void Main(string[] args)
{
Console.WriteLine($"{args[0]},{args[1]}");
}
Static Using Statements
using static System.Console;
static void Main(string[] args)
{
WriteLine(“test”);
}
Declaration Expressions
var cppHelloWorld = new Dictionary<int, string>
{
[10] = "main{",
[20] = " printf(\"hello,world\")",
[30] = "}"
};
Exception-Handling Improvements
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System.ComponentModel;
using System.Runtime.InteropServices;
// ...
[TestMethod][ExpectedException(typeof(Win32Exception))]
public void ExceptionFilter_DontCatchAsNativeErrorCodeIsNot42()
{
try
{
throw new Win32Exception(Marshal.GetLastWin32Error());
}
catch (Win32Exception exception)
if (exception.NativeErrorCode == 0x00042)
{
// Only provided for elucidation (not required).
Assert.Fail("No catch expected.");
}
}
try
{
WebRequest webRequest =
WebRequest.Create("http://IntelliTect.com");
WebResponse response =
await webRequest.GetResponseAsync();
// ...
}
catch (WebException exception)
{
await WriteErrorToLog(exception);
}
看到Console.WriteLine($"string")写法,一时间不理解$的用途的更多相关文章
- C# String 字符串一些关键理解
#1 :在.Net Framework中,字符总是表示成16位Unicode的代码#2 :String 和string 其实是一样的只是表现形式上不同#3 :string类型被视为基元类型,也就是编译 ...
- 第一个输出程序 Console.WriteLine
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.T ...
- 2015.3.12Arinc424 Tools中SiniArincCls.csParserFile(string sFile)函数正则表达式理解
原文: string RegEx1 = @"(\[ITEM\]\s*=[\S\s]*?(?=\[ITEM\])|\[ITEM\]\s*=[\S\s]*)";//用来识别主记录和后续 ...
- 浅析System.Console.WriteLine()
浅析System.Console.WriteLine() Writeline()函数的功能向 StreamWriter 类写入指定字符串和一行字符,共有19个重载,其与Write()函数的主要区别在于 ...
- C#入门——Console.Write()与Console.WriteLine()
参考:https://blog.csdn.net/qujunyao/article/details/72884670 两者区别: Console.Write("abc"); 输出到 ...
- string 常量池的理解
1: String a="123"; String b="12"+"3"; String c="1"+"23& ...
- VS2015使用技巧 为什么我们可以输入cw后按两下tab键出现console.writeline
镇场诗: 大梦谁觉,水月中建博客.百千磨难,才知世事无常. 今持佛语,技术无量愿学.愿尽所学,铸一良心博客.------------------------------------------ 为什么 ...
- 在浏览器控制台输出内容 console.log(string);
在浏览器控制台中写如数据 1添加 <script type="text/javascript">djConfig = { isDebug: true };< ...
- java面试之String的理解(自我理解)
1.String是基本数据类型吗? 不是,是对象,引用数据类型 2.String是可变吗? 不可变,String是final类型的. 3.怎样比较两个字符串的值相同,怎样比较两个字符串是否为同一对象? ...
随机推荐
- python 报错 TabError: inconsistent use of tabs and spaces in indentation
写python的时候如果出现如题的错误 TabError: inconsistent use of tabs and spaces in indentation 意为:制表符错误:缩进中制表符和空格使 ...
- 字体图标库 IcoMoon IconFont Font Awesome的使用
在项目开发的过程中,我们会经常用到一些图标.但是我们在使用这些图标时,往往会遇到失真的情况,而且图片数量很多的话,页面加载就越慢.所以,我们可以使用字体图标的方式来显示图标,字体图标任意放大缩小不会失 ...
- 中国建设工程造价管理系统 http://zaojiasys.jianshe99.com/cecaopsys/
建造师造价管理系统漏洞提示: 可以绕过,直接进入后台,为了安全起见,我就不多说了,. 里面的数据,从小学,中学,高中,大学,户口,电话,身份等, 很全, 本人没有破坏任何数据,
- RBMQ发布和订阅消息
RBMQ发布和订阅消息 exchange 参考翻译自: RabbitMQ官网 生产者并非将消息直接发送到queue,而是发送到exchange中,具体将消息发送到特定的队列还是多个队列,或者是丢弃,取 ...
- dp背包问题
0-1背包 1.问题定义: 给定n种物品和背包.物品i的重量是wi,价值是vi,每种物品只有一个,背包容量为C.问:应该如何选择装入背包的物品,使得装入背包中的物品总值最大. 2.算法思路: 选择装入 ...
- Java基本类型内存字节数
基本类型 字节数 位(bit) 取值范围 byte 1 1*8 -128~127 short 2 2*8 int 4 4*8 long 8 8*8 float 4 4*8 double ...
- logging 使用的一些问题
python 脚本加载是递归加载,被引用的脚本要先与调用者脚本加载,所以不能在函数外部获取logger,否则会导致配置被错过
- week7
catalog 1.面向对象 2.类的继承(续):直接继承与间接继承 3.类方法.静态方法.属性方法 4.getitem 5.反射 6._new_\_metaclass_ 7.异常处理 1.面向对象 ...
- python之路-----前端之html协议一
一.概述 1.1 什么是html语句? 超文本标记语言(Hypertext Markup Language,HTML)通过标签语言来标记要显示的网页中的各个部分.一套规则,浏览器认识的规则 浏览器按顺 ...
- python基础--字典
Python基础--字典 字典的常用函数: dict.clear( )--->无任何返回值 说明: 清除字典内的所有的元素 语法: In [5]: dict.clear? Type: metho ...