标签:string get C# System int 7.0 6.0 using public
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.IO;
using System.Runtime.CompilerServices;
using System.Diagnostics;
using static System.Math; //使用静态类,代码中可以直接调用方法 6.0
using System.Text.RegularExpressions;
namespace ConsoleApp1
{
class Program
{
static void Main(string[] args)
{
User user2 = null;
string uName = user2?.FirstName; //null类型判断,为null返回null 6.0
int? age = user2?.Age;
string myName = $"FirstName is {Name}"; //对字符串格式化简单化 6.0
string uOfName = nameof(user2); //获取字段名称 6.0
Dictionary<int, string> dict1 = new Dictionary<int, string>() { [2] = "re", [43] = "rt" }; //字典初始化 6.0
Dictionary<int, string> dict2 = new Dictionary<int, string>() { { 2, "re" }, { 43, "re" } }; //4.0Ago
get(out int a, out int b); //针对out可以合并 6.0
Console.WriteLine(a);
object obj = "gg";
if (obj is int iObj) //模式匹配 7.0
{
Console.WriteLine(iObj + 9);
}
var tuple = (a: 10, b: "123"); //元组(Tuples)
Console.WriteLine($"a:{tuple.a},b:{tuple.b}");
//解构元组 7.0
var result1 = Get1();
Console.WriteLine($"Item1:{result1.Item1},Item2:{result1.Item2},Item3:{result1.Item3}");
var (str1, int1, dt1) = Get1();
var result2 = Get2();
Console.WriteLine($"Item1:{result2.a},Item2:{result2.b},Item3:{result2.c}");
var (str2, int2, dt2) = Get2();
int num = 123_456; //允许在数字文字中_作为数字分隔符出现 7.0
Console.ReadKey();
}
//解构元组
static (string, int, DateTime) Get1() //7.0
{
return ("abc", 123, DateTime.Now);
}
static (string a, int b, DateTime c) Get2() //7.0
{
return (a: "abc", b: 123, c: DateTime.Now);
}
public static string Get(object a)
{
return GetP();
string GetP() //局部函数,方法中的方法 7.0
{
if (a is int v) return v + "";
if (a is string b) return b;
return "ccc";
}
}
public static void PrintStars(object o)
{
switch (o) //加强版switch 7.0
{
case Print p:
break;
case int a:
break;
case String b when b == "123":
break;
}
}
public class Print
{
public string PrintName { get; set; }
public string MoBanPath { get; set; }
public int Count { get; set; }
}
public static int get(out int a, out int b)
{
a = 8; b = 9;
return a + b;
}
public static string Name { get; set; } = "BB"; //直接对get属性赋初始值 6.0
public static int Age { get; } = 100;
public class User
{
public string FirstName { get; set; }
public string LastName { get; set; }
public override string ToString() => string.Format("{0}——{1}", FirstName, LastName); //Lambda简写方法 6.0
public void S() => string.Format("{0}——{1}", FirstName, LastName);
public string FullName => FirstName + " " + LastName;
public int Age { get; set; } = 35;
public int ID
{
get => 0;
set => Age = value;
}
}
}
}
Bridge_go 发布了32 篇原创文章 · 获赞 8 · 访问量 1万+ 私信 关注
标签:string,get,C#,System,int,7.0,6.0,using,public 来源: https://blog.csdn.net/breakbridge/article/details/104627730
本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享; 2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关; 3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关; 4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除; 5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。