看到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.怎样比较两个字符串的值相同,怎样比较两个字符串是否为同一对象? ...
随机推荐
- mysql 插件相关命令
# 查看mysql的插件 show plugins \G # 安装mysql 插件 INSTALL PLUGIN spartan SONAME 'ha_spartan.so'; # 卸载 UNINST ...
- centos 日志文件
以下介绍的是20个位于/var/log/ 目录之下的日志文件.其中一些只有特定版本采用,如dpkg.log只能在基于Debian的系统中看到./var/log/messages — 包括整体系统信息, ...
- CentOS 配置防火墙操作实例
注:防火墙的基本操作命令: 查询防火墙状态: [root@localhost ~]# service iptables status<回车> 停止防火墙: [root@localh ...
- v模拟器(华为、H3C)点滴
华为模拟器:eNSP V100R002C00B500 安装问题: 1)环境为WIN10,64位专业版 2)安装完成后可以打开界面,但是新建一个设备后,打不开,一直不停的#号 3)解决:手工点击Virt ...
- Arch Linux VMware虚拟机(新手)安装教程
准备工作: 下载好Arch Linux的镜像文件 百度打开Arch官网点击download(下载)转到下载界面,点击磁力下载或者种子下载(官网默认是英文,英文不好的童鞋可以安装浏览器翻译插件,本 ...
- day48-python爬虫学习三
Python的urllib和urllib2模块都做与请求URL相关的操作,但他们提供不同的功能.他们两个最显着的差异如下: urllib2可以接受一个Request对象,并以此可以来设置一个URL的h ...
- 小白的首个maven web项目Step1软件安装一(jdk的下载配置和eclipse的安装)
因为电脑太卡加了一个固态硬盘导致系统重装, 把之前的C盘和D盘合并成一个盘,这下之前下的杂七杂八的软件应该差不多都清干净了. 申请这个博客是想记录最近写项目学习的一些事,系统重装之后,发现自己都已经忘 ...
- 配置solr6.2
1 解压solr ,把 solr-6.2.0\server\solr-webapp下的 webapp 文件夹拷贝到tomcat 的webapps下,重命名为solr,也可以是其他名字: ( 注意,此处 ...
- 浅谈Vector、ArrayList、LinkedList
下图是Collection的类继承图 从图中可以看出:Vector.ArrayList.LinkedList这三者都实现了List 接口.所有使用方式也很相似,主要区别在于实现方式的不同,所以对不同的 ...
- Write CSV file for a dataset
import numpy as np import cv2 as cv2 import os import csv dataste_path = 'datasets/pascal-parts/pasc ...