看到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.怎样比较两个字符串的值相同,怎样比较两个字符串是否为同一对象? ...
随机推荐
- 树莓派 连接 JY901(MPU9250) python 代码
先说BUG,最近要做项目需要树莓派和陀螺仪,资金充足的话肯定是买一个硬件卡尔曼滤波的传感器类似JY901模块,资金不足的就买MPU6050. 网上关于MPU6050在树莓派上的代码还能用,关于JY90 ...
- 【jenkins】jenkins+maven+gitlab+testng,jenkins配置
电脑版本:windows10企业版 jenkins配置: 1.general配置,这里的配置比较简单,基本默认就可以了 2.源码管理 2.1填写git地址,从你的gitlib项目里去找.不会的自行百度 ...
- RuntimeError: Model class app_anme.models.User doesn't declare an explicit app_label and isn't in an application in INSTALLED_APPS.---python学习错误记录
untimeError: Model class app_anme.models.User doesn't declare an explicit app_label and isn't in an ...
- bzoj1688
题解: 暴力枚举生哪一些病 然后判断一下即可 代码: #include<bits/stdc++.h> using namespace std; ,D=; int d,k,n,a[N][D] ...
- LCT模板(无讲解)
怎么说呢,照着打一遍就自然理解了,再打一遍就会背了,再打一遍就会推了. // luogu-judger-enable-o2 #include<bits/stdc++.h> using na ...
- 【转载】用实例给新手讲解RSA加密算法
实践文章:https://mp.weixin.qq.com/s/dCQ17NKWu5ISc-eNhFDlvw 原文地址:http://bank.hexun.com/2009-06-24/1189585 ...
- python pexpect包的一些用法
转自:https://www.jianshu.com/p/cfd163200d12 mark一下,原文中写的挺详细
- mpeg2文件分析(纯c解析代码)
参考链接: 1. MPEG-2码流结构分析 https://www.cnblogs.com/CoderTian/p/9246225.html(本文语法采用这里的截图,代码原创) 1. mpeg2的码流 ...
- C++中_T的用途
1 C++语言中“_T”是什么意思? Visual C++里边定义字符串的时候,用_T来保证兼容性,VC支持ascii和unicode两种字符类型,用_T可以保证从ascii编码类型转换到uni ...
- 【转载】IL指令集
转载自:http://www.cnblogs.com/knowledgesea/p/5461040.html 名称 说明 Add 将两个值相加并将结果推送到计算堆栈上. Add.Ovf 将两个整数相加 ...