IEnumerable。 T代表什么?,请帮助我。 [英] IEnumerable . What T stands for?, pls help me out.
本文介绍了IEnumerable。 T代表什么?,请帮助我。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
通常如果我们想要使用Inumerable,我们将使用以下内容。
class program
{
static void main( string [] args)
{
List< int> oyears = new List< int>();
oyears.Add( 100 );
oyears.Add( 101 );
oyears.Add( 102 );
}
IEnumerable< int> enum =(IEnumerable< int>)oyears;
foreach ( int i in enum )
{
console.wriline(i);
}
输出:
101
102.
这里IEnumerable< int> ,int是数据类型。那么什么是IEnumerable< T>。 T是什么或代表什么?..请帮帮我。
解决方案
IEnumerable< T>
interface基本上是类型安全的IEnumerable
。在这种情况下,T
是所谓的泛型类型参数。它定义IEnumerable
将包含T
类型的对象。
在互联网上使用泛型有很多资源,这里有一些开始:
泛型简介(C#编程指南) [ ^ ]
IEnumerable和IEnumerable< T> 之间的差异[ ^ ]
C#IEnumerable [< a href =http://www.dotnetperls.com/ienumerabletarget =_ blanktitle =New Window> ^ ]
IEnumerab乐< T>是一个接口 - 你不能创建一个IEnumerable< t>,而是必须创建一个实现IEnumerable< t>< / t>< / t>< / t><的类/ BLOCKQUOTE>
hi, usually if we want use Inumerable, we will use follows.
class program { static void main(string[] args) { List<int> oyears=new List<int>(); oyears.Add(100); oyears.Add(101); oyears.Add(102); } IEnumerable<int> enum=(IEnumerable<int>) oyears; foreach(int i in enum) { console.wriline(i); }
output :
101
102.
here IEnumerable<int> , int is datatype. so What is IEnumerable<T>. here T is What or stands for?..please help me out.解决方案TheIEnumerable<T>
interface is basically a type-safeIEnumerable
. TheT
in this case is a so called generic type parameter. It defines that theIEnumerable
will contain objects of typeT
.
There's a lot of resources to find on using generics on the internet, here's some to get started:
Introduction to Generics (C# Programming Guide)[^]
Difference between IEnumerable and IEnumerable<T>[^]
C# IEnumerable[^]
IEnumerable<t> is an interface - you can't create an IEnumerable<t>, but rather must create some class that implements IEnumerable<t></t></t></t>
这篇关于IEnumerable。 T代表什么?,请帮助我。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文