用过VB的童鞋都知道VB中有With关键字,可以省略每次重复写对象名。
C#中有没有呢?其实是有的,在C#中初始化对象时,是有类似的写法的,请参看下面的code。
vb code
dim u as new user;
with user
.id = 123456
.name = "Username"
.password = "pwd"
end with
C# code
User u = new User()
{
id = 123456
name = "Username"
password = "pwd"
};