我发现 Pascal 的一个非常有用的功能是能够命名数据类型,例如
type
person: record
name: string;
age: int;
end;
var
me: person;
you: person;
etc
你能在 C# 中做类似的事情吗?我希望能够做类似的事情
using complexList = List<Tuple<int,string,int>>;
complexList peopleList;
anotherList otherList;
这样,如果我必须更改数据类型的定义,我可以在一处完成。
C# 是否支持实现此目的的方法?
是的,这是可能的。工作示例在这里 https://dotnetfiddle.net/WucQad。
你可以写:
using System;
using System.Collections.Generic;
namespace ConsoleApplication12
{
using MyAlias = List<Tuple<int, string, int>>;
}
或者,如果在命名空间之外声明:
using System;
using System.Collections.Generic;
using MyAlias = System.Collections.Generic.List<System.Tuple<int, string, int>>;
namespace ConsoleApplication12
{
}
然后将其用作类型:
MyAlias test = new MyAlias();
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)