通用参数必须实现“转移”。手术 [英] Generic param must implement "shift" operation

查看:66
本文介绍了通用参数必须实现“转移”。手术的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,


我想写一个这样做的通用类:


公共类X(Of T)

Public Sub方法(param为T)

dim x为T = param> 3

End Sub

End类


因此,我需要将T约束为实现>>类型的类型。运营商。

有没有办法做到这一点?


TIA - Bob

解决方案

< blockquote>Bob Altman < rd*@nospam.nospamschrieb


大家好,


我想写一个执行此操作的泛型类:


公共等级X(Of T)

公共子方法(param为T)

dim x为T = param> ; 3

结束子

结束类


因此,我需要将T约束为实现>的类型>"运营商。

有没有办法做到这一点?



不,可能不是。请参阅主题基础数字类型?三天前。


你打算用这种类型做什么?如果它只是转移,你

就不需要这个Sub。

Armin


嗨Bob,


是的,如果你的泛型类的某个方法会调用参数

object'的特定运算符,你需要制作确保传递的参数

对象支持某个运算符。在VB.NET 9(来自VS 2005)中,VB.NET

已经开始支持运算符重载:


#Overloading VB.NET 2.0中的运算符
http://www.developer.com/net/ vb / arti ... 0926_3512311_2


此致,


Steven Cheng


Microsoft MSDN在线支持主管


================================ ==================


通过电子邮件收到我的帖子通知?请参阅
http://msdn.microsoft .com / subscripti ... ult.aspx#notif

ications。


注意:MSDN托管新闻组支持服务是针对非紧急问题

如果社区或微软支持人员在1个工作日内做出初步回复是可以接受的。请注意,每个跟随

的响应可能需要大约2个工作日作为支持

专业人士与您合作可能需要进一步调查才能达到

最有效的分辨率。该产品不适用于需要紧急,实时或基于电话的交互或复杂的b $ b项目分析和转储分析问题的情况。这种性质的问题最好通过联系

Microsoft客户支持服务(CSS)处理
href =http://msdn.microsoft.com/subscriptions/support/default.aspx\"target =_ blank> http://msdn.microsoft.com/subscripti...t/default.aspx


==================================== ==============

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



--------------------
< blockquote class =post_quotes>
> From:" Bob Altman" < rd*@nospam.nospam>
主题:通用参数必须实现转移。操作
日期:2007年12月10日星期一09:58:59 -0800
大家好,

我想编写一个通用类来执行此操作:


公共等级X(Of T)

公共子方法(参数为T)

dim x为T = param> 3

End Sub

结束类

因此,我需要将T约束为实现>>的类型。运营商。有没有办法做到这一点?

TIA - Bob


" Steven Cheng [MSFT]" ; < st ***** @ online.microsoft.comschrieb


嗨鲍勃,


是的,如果你的通用class''s



这些类不是类,而是值类型,称为SByte,Byte,Short,

UShort,Integer,UInteger,Long ,或者说ULONG。


他在找什么就像


Public Sub Method(Of T As {SByte,Byte,Short, UShort,Integer,UInteger,

Long,ULong})()

End Sub


这显然是不可能的。所以,只剩下方法重载。


某些方法会调用参数

对象'的特定运算符,你需要确定传递的

参数对象支持某个运算符。在VB.NET 9中(来自

VS 2005),VB.NET已经开始支持运算符重载:


#Overloading VB.NET 2.0中的运算符
http://www.developer.com/net/ vb / arti ... 0926_3512311_2



>运算符是一个VB.Net本机运算符,只能应用于

类型上文提到的。因此我在上一篇文章中的问题还有什么呢?
必须对传递的值进行。

Armin

Hi all,

I want to write a generic class that does this:

Public Class X (Of T)
Public Sub Method(param As T)
dim x as T = param >3
End Sub
End Class

So, I need to constrain T to types that implement the ">>" operator. Is
there a way to do this?

TIA - Bob

解决方案

"Bob Altman" <rd*@nospam.nospamschrieb

Hi all,

I want to write a generic class that does this:

Public Class X (Of T)
Public Sub Method(param As T)
dim x as T = param >3
End Sub
End Class

So, I need to constrain T to types that implement the ">>" operator.
Is there a way to do this?


No, probably not. See topic "base numeric type?" three days ago.

What else do you intend to do with this type? If it was only shifting, you
wouldn''t need this Sub.
Armin


Hi Bob,

Yes, if your generic class''s certain method will call the parameter
object''s particular operator, you need to make sure the passed parameter
objects support the certain operator. In VB.NET 9 (from VS 2005), VB.NET
has started supporting operator overload:

#Overloading Operators in VB.NET 2.0
http://www.developer.com/net/vb/arti...0926_3512311_2

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead

==================================================

Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscripti...ult.aspx#notif
ications.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscripti...t/default.aspx.

==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.


--------------------

>From: "Bob Altman" <rd*@nospam.nospam>
Subject: Generic param must implement "shift" operation
Date: Mon, 10 Dec 2007 09:58:59 -0800

Hi all,

I want to write a generic class that does this:

Public Class X (Of T)
Public Sub Method(param As T)
dim x as T = param >3
End Sub
End Class

So, I need to constrain T to types that implement the ">>" operator. Is
there a way to do this?

TIA - Bob


"Steven Cheng[MSFT]" <st*****@online.microsoft.comschrieb

Hi Bob,

Yes, if your generic class''s

The classes are not classes but value types called SByte, Byte, Short,
UShort, Integer, UInteger, Long, or ULong.

What he is looking for is something like

Public Sub Method(Of t As {SByte, Byte, Short, UShort, Integer, UInteger,
Long, ULong})()
End Sub

which obviously is not possible. So, only method overloading is left.

certain method will call the parameter
object''s particular operator, you need to make sure the passed
parameter objects support the certain operator. In VB.NET 9 (from
VS 2005), VB.NET has started supporting operator overload:

#Overloading Operators in VB.NET 2.0
http://www.developer.com/net/vb/arti...0926_3512311_2


The >operator is a VB.Net native operator that can only be applied to the
types mentioned above. Therefore the question in my previous post what else
has to be done to the value passed.
Armin


这篇关于通用参数必须实现“转移”。手术的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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