看到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.怎样比较两个字符串的值相同,怎样比较两个字符串是否为同一对象? ...
随机推荐
- Sublime Text3安装evernote插件
关键字 Markdown编辑器.Evernote.Sublime Text3 正文 Sublime Text3安装evernote插件方法如下: 1.使用Package Control安装ever ...
- JSP 标准标签库JSTL
JSP标准标签库(JSTL)是一个JSP标签集合,它封装了JSP应用的通用核心功能. JSTL支持通用的.结构化的任务,比如迭代,条件判断,XML文档操作,国际化标签,SQL标签. 除了这些,它还提供 ...
- 一条shell命令让多台Linux服务器执行
1.环境 局域网环境有3台Linux服务器,配置host文件 [root@master1 ~]# vim /etc/hosts 192.168.8.201 master1 192.168.8.202 ...
- python小游戏,石头/剪子/布
#从控制台输入石头(1)/剪子(2)/布(3) player=int(input("玩家出拳 石头(1)/剪子(2)/布(3)")) #电脑随机出拳 computer comput ...
- Java打包小结
1eclipse打包:点击项目export,然后点击java->JAR file->next->选择目录->finish->报错也不管 2idea直接运行jar包就好了, ...
- ASP.NET MVC Display Mode 移动端视图 配置对微信内置浏览器的识别
最近在捣鼓一个稍微有点low的商城网站,没有计划做app却要求有个wap版,而前端又没有做成响应式,时间WTF,直接利用了asp.net mvc的Display Mode Provider. 使用方式 ...
- ldap 导出、导入ldif数据
ldap 导出.导入ldif数据有如下方式: 1.dsadm(速度快,需要停止ldap实例) 2.dsconf(速度慢,需要保持ldap实例开启) windows导出.导入需要加上参数--unsecu ...
- Mac中java实现自动打开软件问题
Runtime.getRuntime().exec("/Applications/NetEaseMusic.app/Contents/MacOS/NetEaseMusic");遗留 ...
- Python标准库--time模块的详解
time模块 - - -时间获取和转换 在我们学习time模块之前需要对以下的概念进行了解: 时间戳:时间戳是指格林威治时间1970年01月01日00时00分00秒(北京时间1970年01月01日08 ...
- open还是codecs.open区别
>>> fr = open('test.txt','a')>>> line1 = "我是一道光">>> fr.write(li ...