任何可能的使用此功能? [英] any possible use of this feature?

查看:110
本文介绍了任何可能的使用此功能?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您可以定义两个具有相同名称的类,但在一个程序集中具有不同的通用

参数。如下:


class Gen< T>

{

}


Gen Gen< T1,T2>

{

}


任何可能的用途?

解决方案

类名必须在一个名称空间内是唯一的。如果你必须定义两个具有相同名称的
类,你可以将它们放在一个

程序集中的不同名称空间中。 C#类不支持模板接收参数,如C ++中


-

此帖子提供按现状没有保证,也没有赋予任何权利。

" Justin Shen" <德******* @ hotmail.com>在留言中写道

新闻:es ************** @ TK2MSFTNGP10.phx.gbl ...

你可以定义两个类具有相同的名称,但在一个程序集中具有不同的通用
参数。如下:

类Gen< T>
{
}
类Gen< T1,T2>
{
}

任何可能的用途?



王家川[MSFT]< ji **** *@online.microsoft.com>写道:

类名必须在一个名称空间内是唯一的。如果必须定义两个具有相同名称的类,可以将它们放在一个
程序集中的不同名称空间中。 C#类不支持模板接收参数,比如在C ++中



的泛型v2。


-

Jon Skeet - < sk *** @ pobox.com>
http://www.pobox.com/~skeet

如果回复群组,请不要给我发邮件


Justin Shen< De ******* @ hotmail.com>写道:

您可以定义两个具有相同名称但在一个程序集中具有不同通用
参数的类。如下:

类Gen< T>
{
}
类Gen< T1,T2>
{
}

任何可能的用途?




可能 - 我可以想象一些像数组列表的东西

但是有多个尺寸,每个尺寸都是不同的

类型。例如,你可以这样做:


myList [10," hello"] =" there";


使用直接泛型ArrayList你可以很容易地找到


myList [10] [" hello"] =" there";


我怀疑,但是在某些情况下,第一种语法可能会更好。


可能不是*非常有用,但只是想知道如何使用它。


-

Jon Skeet - < sk *** @ pobox.com>
http://www.pobox.com/~skeet

如果回复小组,请不要给我发邮件


you can define two class with same name but having different generic
parameters in one assembly. As below:

class Gen<T>
{
}

class Gen<T1,T2>
{
}

any possible use of it?

解决方案

class name has to be unique within one namespace. If you have to define two
classes with same name, you can put them in different namespaces in one
assembly. C# class does not support template taking parameters like in C++

--
This posting is provided "AS IS" with no warranties, and confers no rights.
"Justin Shen" <De*******@hotmail.com> wrote in message
news:es**************@TK2MSFTNGP10.phx.gbl...

you can define two class with same name but having different generic
parameters in one assembly. As below:

class Gen<T>
{
}

class Gen<T1,T2>
{
}

any possible use of it?



Jiachuan Wang [MSFT] <ji*****@online.microsoft.com> wrote:

class name has to be unique within one namespace. If you have to define two
classes with same name, you can put them in different namespaces in one
assembly. C# class does not support template taking parameters like in C++



I think Justin was actually talking about the generics which will be
available in C# v2.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too


Justin Shen <De*******@hotmail.com> wrote:

you can define two class with same name but having different generic
parameters in one assembly. As below:

class Gen<T>
{
}

class Gen<T1,T2>
{
}

any possible use of it?



Possibly - I could imagine something which would be like an array-list
but with multiple "dimensions", each of which would be a different
type. For instance, you could do:

myList[10,"hello"] = "there";

With straight generics on ArrayList you could easily get to

myList[10]["hello"] = "there";

I suspect, but the first syntax might be better in some circumstances.

Probably not *really* useful, but just an idea of how it might be used.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too


这篇关于任何可能的使用此功能?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆