定义类型别名 [英] Defining type aliases
本文介绍了定义类型别名的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
帕斯卡的一个功能,我发现非常有用的是命名一个数据类型的能力,如:
One feature of Pascal I found very useful was the ability to name a data type, eg
type
person: record
name: string;
age: int;
end;
var
me: person;
you: person;
etc
您可以做在C#中类似的东西?我希望能够做一些像
Can you do something similar in C#? I want to be able to do something like
using complexList = List<Tuple<int,string,int>>;
complexList peopleList;
anotherList otherList;
所以,如果我要改变数据类型的定义,我可以在一个地方做。
So that if I have to change the definition of the datatype, I can do it in one place.
请问C#支持的方式来实现这一目标?
Does C# support a way to achieve this?
推荐答案
这是不excatly你帕斯卡尔做什么,而是你可以使用使用
-directive。看看这里的如何使用它
It's not excatly what you do in Pascal, but you can use the using
-directive. Have a look here on how to use it
例如:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using MyList = Dummy2.CompleXList;
namespace Dummy2
{
public class Person
{
}
public class CompleXList : List<Person>
{
}
class Program
{
static void Main(string[] args)
{
MyList l1 = new MyList();
}
}
}
这篇关于定义类型别名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文