一:什么是.NetFrameWork/ CLR / C#

1:.NetFramework即架构,它是一个语言开发软件,提供了软件开发的框架,使开发更具工程性、简便性和稳定性,这个框架主要是针对于c#语言的,该框架包含了CLR,VS等编译工具,BCL(基本类库)。

2:c#是一个简单的、现代的、通用的、面向对象的编程语言,它是由微软(Microsoft)开发的,主要是为.netFramwork框架提供一种编程规范,即是符合CLR中的CLS(通用语言规范)。

3:CLR是Common Language RunTime,公共运行类库。c#语言通过编译会生成IL+Metadata两部分,而CL主要的功能是通过JIT即时编译器把这部分解析成机器识别的代码,即二进制编码,然后再计算机中执行。

二:c# Project运行的整个流程

执行流程:

无论是VB或者C#项目都会依赖于BCL(基础类库),然后通过编译生成IL(中间语言)+Metadata(列表清单),然后通过JIT(Just IN Time )编译成机器二进制码(因为计算机只识别二进制码),然后再在计算机中执行。

三:.NetFrameWork/ CLR / C#对应的版本

注意:并不是每个版本都一一对应的,有的版本升级然后CLR并没有升级,visualStudio是.net开发工具。

下图也能说明vs与c#版本:

四:c#既然是.netFramework的规范,那下面介绍一下c#6以及c#7新的语法

1:c#6的新语法

如图:

具体代码如下:

 using System;
using System.Collections.Generic;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using static System.Math; namespace Test.Project
{
/// <summary>
/// C#6 新语法
/// </summary>
public class SharpSix
{
#region 自动属性初始化(Auto-property initializers)
public string Name { get; set; } = "summit";
public int Age { get; set; } = ;
public DateTime BirthDay { get; set; } = DateTime.Now.AddYears(-);
public IList<int> AgeList
{
get;
set;
} = new List<int> { , , , , };
#endregion public void Show(People peopleTest)
{
#region 字符串嵌入值(String interpolation)
Console.WriteLine($"年龄:{this.Age} 生日:{this.BirthDay.ToString("yyyy-MM-dd")}");
Console.WriteLine($"年龄:{{{this.Age}}} 生日:{{{this.BirthDay.ToString("yyyy -MM-dd")}}}"); Console.WriteLine($"{(this.Age <= 22 ? "小鲜肉" : "老鲜肉")}");
#endregion #region 导入静态类(Using Static)
Console.WriteLine($"之前的使用方式: {Math.Pow(4, 2)}");
Console.WriteLine($"导入后可直接使用方法: {Pow(4, 2)}");
#endregion #region 空值运算符(Null-conditional operators)
int? iValue = ;
Console.WriteLine(iValue?.ToString());//不需要判断是否为空
string name = null;
Console.WriteLine(name?.ToString());
#endregion #region 对象初始化器(Index Initializers)
IDictionary<int, string> dictOld = new Dictionary<int, string>()
{
{ ,"first"},
{ ,"second"}
}; IDictionary<int, string> dictNew = new Dictionary<int, string>()
{
[] = "first",
[] = "second"
}; #endregion #region 异常过滤器(Exception filters)
int exceptionValue = ;
try
{
Int32.Parse("s");
}
catch (Exception e) when (exceptionValue > )//满足条件才进入catch
{
Console.WriteLine("catch");
//return;
}
#endregion #region nameof表达式 (nameof expressions)
Console.WriteLine(nameof(peopleTest)); //获取peopleTest这个字符串
#endregion #region 在cath和finally语句块里使用await(Await in catch and finally blocks) #endregion
} #region 在属性/方法里使用Lambda表达式(Expression bodies on property-like function members)
public string NameFormat => string.Format("姓名: {0}", "summit");
public void Print() => Console.WriteLine(Name);
#endregion
} public class People
{
public int Id { get; set; }
public string Name { get; set; } public static async Task Get()
{
await Task.Run(() =>
{ Thread.Sleep();
Console.WriteLine("People.async.Get");
});
Console.WriteLine("People.async.Get after");
}
}
}

2:c#7的新语法

 using System;
using System.Collections.Generic;
using System.Text; namespace Test.Project
{
/// <summary>
/// c#7新语法
/// </summary>
public class SharpSeven
{
public void Show()
{
#region out参数
{
this.DoNoting(out int x, out int y);
Console.WriteLine(x + y); this.DoNoting(out var l, out var m); }
//Console.WriteLine(x + y);
#endregion #region 模式
this.PrintStars(null);
this.PrintStars(); this.Switch(null);
this.Switch("RichardRichard");
this.Switch("Richard");
#endregion #region 元组
{
var result = this.LookupName();
Console.WriteLine(result.Item1);
Console.WriteLine(result.Item2);
Console.WriteLine(result.Item3); }
{
var result = this.LookupNameByName();
Console.WriteLine(result.first);
Console.WriteLine(result.middle);
Console.WriteLine(result.last); Console.WriteLine(result.Item1);
Console.WriteLine(result.Item2);
Console.WriteLine(result.Item3);
}
#endregion #region 局部函数
{
Add();
int Add(int k)//闭合范围内的参数和局部变量在局部函数的内部是可用的,就如同它们在 lambda 表达式中一样。
{
return + k;
}
}
#endregion #region 数字分隔号
long big = 100_000;
#endregion } /// <summary>
/// System.ValueTuple 需要安装这个nuget包
/// </summary>
/// <param name="id"></param>
/// <returns></returns>
private (string, string, string) LookupName(long id) // tuple return type
{
return ("first", "middle", "last");
} private (string first, string middle, string last) LookupNameByName(long id) // tuple return type
{
return ("first", "middle", "last");
//return (first: "first", middle: "middle", last: "last");
} /// <summary>
/// 具有模式的 IS 表达式
/// </summary>
/// <param name="o"></param>
public void PrintStars(object o)
{
if (o is null) return; // 常量模式 "null"
if (!(o is int i)) return; // 类型模式 定义了一个变量 "int i"
Console.WriteLine(new string('*', i));
} /// <summary>
/// 可以设定任何类型的 Switch 语句(不只是原始类型)
/// 模式可以用在 case 语句中
/// Case 语句可以有特殊的条件
/// </summary>
/// <param name="text"></param>
private void Switch(string text)
{
int k = ;
switch (text)
{
case "RichardRichard" when k > :
Console.WriteLine("RichardRichard");
break;
case "Richard" when text.Length < :
Console.WriteLine("Richard");
break;
case string s when s.Length > ://模式
Console.WriteLine(s);
break;
default:
Console.WriteLine("default");
break;
case null:
Console.WriteLine("null");
break;
}
} private void DoNoting(out int x, out int y)
{
x = ;
y = ;
}
}
}

深度解析.NetFrameWork/CLR/C# 以及C#6/C#7新语法的更多相关文章

  1. [WebKit内核] JavaScript引擎深度解析--基础篇(一)字节码生成及语法树的构建详情分析

    [WebKit内核] JavaScript引擎深度解析--基础篇(一)字节码生成及语法树的构建详情分析 标签: webkit内核JavaScriptCore 2015-03-26 23:26 2285 ...

  2. [WebKit内核] JavaScriptCore深度解析--基础篇(一)字节码生成及语法树的构建

    看到HorkeyChen写的文章<[WebKit] JavaScriptCore解析--基础篇(三)从脚本代码到JIT编译的代码实现>,写的很好,深受启发.想补充一些Horkey没有写到的 ...

  3. 第37课 深度解析QMap与QHash

    1. QMap深度解析 (1)QMap是一个以升序键顺序存储键值对的数据结构 ①QMap原型为 class QMap<K, T>模板 ②QMap中的键值对根据Key进行了排序 ③QMap中 ...

  4. Deep Learning模型之:CNN卷积神经网络(一)深度解析CNN

    http://m.blog.csdn.net/blog/wu010555688/24487301 本文整理了网上几位大牛的博客,详细地讲解了CNN的基础结构与核心思想,欢迎交流. [1]Deep le ...

  5. (转载)(收藏)OceanBase深度解析

    一.OceanBase不需要高可靠服务器和高端存储 OceanBase是关系型数据库,包含内核+OceanBase云平台(OCP).与传统关系型数据库相比,最大的不同点, 是OceanBase是分布式 ...

  6. Kafka深度解析

    本文转发自Jason’s Blog,原文链接 http://www.jasongj.com/2015/01/02/Kafka深度解析 背景介绍 Kafka简介 Kafka是一种分布式的,基于发布/订阅 ...

  7. java内存分配和String类型的深度解析

    [尊重原创文章出自:http://my.oschina.net/xiaohui249/blog/170013] 摘要 从整体上介绍java内存的概念.构成以及分配机制,在此基础上深度解析java中的S ...

  8. Unity加载模块深度解析(Shader)

    作者:张鑫链接:https://zhuanlan.zhihu.com/p/21949663来源:知乎著作权归作者所有.商业转载请联系作者获得授权,非商业转载请注明出处. 接上一篇 加载模块深度解析(二 ...

  9. Unity加载模块深度解析(网格篇)

    在上一篇 加载模块深度解析(一)中,我们重点讨论了纹理资源的加载性能.这次,我们再来为你揭开其他主流资源的加载效率. 这是侑虎科技第53篇原创文章,欢迎转发分享,未经作者授权请勿转载.同时如果您有任何 ...

随机推荐

  1. nginx 安装 lua_nginx_module 模块(nginx——lua 学习笔记1)

    插入两个网站: nginx + lua 的OpenResty 开发 跟我学OpenResty(Nginx+Lua)开发目录贴 两个都是 可以根据目录一步步学习的. 1. 版本下载 nginx版本为 n ...

  2. postman---postman参数化

    我们在做接口测试的过程中,都会遇到同一个接口不同的数据,每次去一个个填写数据就太麻烦了,今天我们一起学习下如何通过postman进行参数化 参数化 参数化就是1个接口请求不同的数据,我们可以通过把请求 ...

  3. is ==的区别 编码和解码

    1.n=0 n1=0 print(n==n1) ==>true  == 是比较两边的值 2.a="alex " b="alex" print(a==b)= ...

  4. 浅谈[].slice.call(arguments, 1)

    今天在跟踪调试项目的代码时,发现在一个function中用到了这么一段[].slice.call(arguments, 1) 的代码.心中便起了疑惑,对于slice 和 call 的方法,倒是不怎么陌 ...

  5. centos7下安装配置prometheus

    prometheus官网:https://prometheus.io/download/ 搭建环境参考:https://blog.csdn.net/baidu_36943075/article/det ...

  6. 1.web2

    听说聪明的人都能找到答案http://123.206.87.240:8002/web2/ 直接查看源码~~~

  7. shellnet运行train_val_seg.py

    1.semantic3d数据集准备:prepare_semantic3d_data.py 11个测试数据集(.txt文件): 假如运行的是室外点云数据集“seg_semantic3d”,可能需要做以下 ...

  8. bzoj2093 Frog

    题目链接 思路 非常有趣的一道题. 先考虑如何找出第K远的位置. 因为给出的序列是单调的,所以对于位置\(i\)的前\(K\)远位置肯定是一个包含位置\(i\)的长度为\(k+1\)的区间.我们用\( ...

  9. Paper | Fast image processing with fully-convolutional networks

    目录 故事 方法 实验 发表在2017年ICCV. 核心任务:加速图像处理算子(accelerate image processing operators). 核心方法:将算子处理前.后的图像,训练一 ...

  10. 弄明白kubernetes中的“三种IP”

    Node IP : Node节点的IP地址 Pod IP:Pod的IP地址 Cluster IP : Service 的IP地址 首先,Node IP是Kubernetes集群中每个节点(服务器)物理 ...