看到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.怎样比较两个字符串的值相同,怎样比较两个字符串是否为同一对象? ...
随机推荐
- Element-ui上传文件(删除、添加、预览)
先看下效果是不是你所需要的.... 上传文件进度条后续会加上的.... 功能需求:默认为上传状态 1.未上传:点击可上传文件 2.已上传:点击可上传文件 (1).鼠标移入[删除] (2).鼠标点击[预 ...
- 国外服务器:org.xml.sax.SAXParseException
改为: xsi:schemaLocation="http://www.springframework.org/schema/beans classpath:org/springframewo ...
- (整理4)RPC服务和HTTP服务简单说明
很长时间以来都没有怎么好好搞清楚RPC(即Remote Procedure Call,远程过程调用)和HTTP调用的区别,不都是写一个服务然后在客户端调用么?这里请允许我迷之一笑~Naive!本文简单 ...
- 集合框架之map
Map实现类用于保存具有映射关系的数据.Map保存的每项数据都是key-value对,也就是由key和value两个值组成.Map里的key是不可重复的,key用户标识集合里的每项数据. Map提供了 ...
- css的em是根据什么来写的
em是要依靠父元素的值来计算的 1.字体计算公式依旧 1 ÷ 父元素的font-size × 需要转换的像素值 = em值 转自:https://zhidao.baidu.com/question/7 ...
- Mac搭建SVN服务器+Cornerstone连接服务器
Mac自带svn,我们只需配置并开启就可以了,打开终端,输入svnserve --version查看svn版本 可以看到我的mac自带的svn版本号为1.9.7,下面开始配置服务器: 1.终端输入su ...
- Python_Mix*re模块,元字符,量词
模块: 模块就是一组功能的集合,你要和某个东西打交道,而这个东西本身和Python没有关系,这个东西本身就存在,Python提供了一个功能的集合,专门负责和这个东西打交道. 模块的类型: 内置模块 不 ...
- 用Tensorflow搭建神经网络的一般步骤
用Tensorflow搭建神经网络的一般步骤如下: ① 导入模块 ② 创建模型变量和占位符 ③ 建立模型 ④ 定义loss函数 ⑤ 定义优化器(optimizer), 使 loss 达到最小 ⑥ 引入 ...
- JAVA----线程初级
一.认识多任务.多进程.单线程.多线程 要认识多线程就要从操作系统的原理说起. 以前古老的DOS操作系统(V 6.22)是单任务的,还没有线程的概念,系统在每次只能做一件事情.比如你在copy东西 ...
- git解决代码冲突
1.当项目开发是几个人的时候,难免会出现代码冲突,使用git命令行解决冲突的方法如下: git checkout develop git pullgit checkout feature/新建会员功能 ...