C#语法糖
C#语法糖
最近看到代码中有语法糖,记录一下,
1.重写,只能重写,属性,虚方法(virtual),子类重写用override
private string a
public string A
{
get =>“123”;
set =>a=value;
}
2.定义静态变量赋值
private static Lazy<KafkaProducer> Producer { get; } = new Lazy<KafkaProducer>(() => new KafkaProducer(_kafkaConfigDic), true);
静态属性,类初始化就会执行
3.给引用的对象区别名
using Common.Logging;
using Tuhu.WinService.ConsumerForPush.Kafka;
using System;
using System.Threading.Tasks;
using KafkaMessage = Confluent.Kafka.Message<Confluent.Kafka.Null, string>;