比较空值类型 [英] Comparing Empty Value types

查看:67
本文介绍了比较空值类型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在类型颜色类中有一个公共变量,声明如下:

public mycolor as color = color.Empty


我想检查用户是否指定了一种颜色;


如果mycolor = Color.Empty则.....



如果mycolor是Color.Empty然后.......


我得到错误说=可以用于颜色而且不可能与

值类型一起使用。我放弃了...我该怎么做。谢谢。

-

Dennis在休斯顿

I have a public variable in a class of type color declared as follows:

public mycolor as color = color.Empty

I want to check to see if the user has specified a color like;

if mycolor = Color.Empty then.....
or
if mycolor is Color.Empty then .......

I get errors saying that = can be used for colors and is can''t be used with
value types. I give up...how do I do this. Thanks.
--
Dennis in Houston

推荐答案

由于ValueType派生自Object,你可以使用Equals方法。对于

值类型,如果实例的类型相同且

具有相同的值,则返回true。


如果mycolor.Equals(Color.Empty)然后

MessageBox.Show(mycolor is empty)

结束如果


希望有所帮助..

Imran。

" Dennis" <德**** @ discussions.microsoft.com>在消息中写道

新闻:9A ********************************** @ microsof t.com ...
Since ValueType derives from Object, you can use the Equals method. For
Value Types, this returns true if the instances are of the same type and
have the same value.

If mycolor.Equals(Color.Empty) Then
MessageBox.Show("mycolor is Empty")
End If

hope that helps..
Imran.
"Dennis" <De****@discussions.microsoft.com> wrote in message
news:9A**********************************@microsof t.com...
我在类型颜色类中有一个公共变量,声明如下:

public mycolor as color = color.Empty

我想查看用户是否指定了一种颜色;

如果mycolor = Color.Empty则.....

如果mycolor是Color.Empty然后.......

我得到错误,说=可以用于颜色,不能用
值类型。我放弃了...我该怎么做。谢谢。
-
Dennis in Houston
I have a public variable in a class of type color declared as follows:

public mycolor as color = color.Empty

I want to check to see if the user has specified a color like;

if mycolor = Color.Empty then.....
or
if mycolor is Color.Empty then .......

I get errors saying that = can be used for colors and is can''t be used
with
value types. I give up...how do I do this. Thanks.
--
Dennis in Houston



Dennis,

您是否尝试过Equals功能或等于运算符?


如果mycolor.Equals(Color.Empty)那么


结束如果


要使用Equals运算符,您需要调用

创建的共享函数。


如果Color.op_Equality(mycolor,Color.Empty)然后


结束如果


请参阅在线帮助中的Color.Equals功能以获得一些重要的评论

about使用Color.Equals时你可能想用Color.ToArgb来比较两种颜色。


如果mycolor.ToArgb()= Color.Empty。 ToArgb()然后


结束如果

注意:VS.NET 2005(又名Whidbey,将于2005年晚些时候发布)将支持调用

等于运算符的熟悉的=句法。有关VS.NET

2005的信息,请参阅 http:/ /lab.msdn.microsoft.com/vs2005/


''VS.NET 2005样本

如果mycolor = Color.Empty那么


结束如果


希望这有帮助

Jay


"丹尼斯" <德**** @ discussions.microsoft.com>在消息中写道

新闻:9A ********************************** @ microsof t.com ...
Dennis,
Did you try the Equals function or the Equals Operator?

If mycolor.Equals(Color.Empty) Then

End If

To use the Equals Operator you need to call the shared function that is
created.

If Color.op_Equality(mycolor, Color.Empty) Then

End If

See the Color.Equals function in the online help for some important remarks
about using Color.Equals and when you may want to use Color.ToArgb to
compare two colors.

If mycolor.ToArgb() = Color.Empty.ToArgb() Then

End If
NOTE: VS.NET 2005 (aka Whidbey, due out later in 2005) will support calling
the Equals Operator with the familiar "=" syntax. For information on VS.NET
2005 see http://lab.msdn.microsoft.com/vs2005/.

'' VS.NET 2005 sample
If mycolor = Color.Empty Then

End If

Hope this helps
Jay

"Dennis" <De****@discussions.microsoft.com> wrote in message
news:9A**********************************@microsof t.com...
我在类型颜色类中有一个公共变量,声明如下:

public mycolor as color = color.Empty

我想查看用户是否指定了一种颜色;

如果mycolor = Color.Empty则.....

如果mycolor是Color.Empty然后.......

我得到错误,说=可以用于颜色,不能用
值类型。我放弃了...我该怎么做。谢谢。
-
Dennis in Houston
I have a public variable in a class of type color declared as follows:

public mycolor as color = color.Empty

I want to check to see if the user has specified a color like;

if mycolor = Color.Empty then.....
or
if mycolor is Color.Empty then .......

I get errors saying that = can be used for colors and is can''t be used
with
value types. I give up...how do I do this. Thanks.
--
Dennis in Houston



Dennis,


作为替代方案

如果mycolor.ToArgb = mycolor.Empty.ToArgb


结束如果


Cor


" Dennis" < De **** @ discuss.microsoft.com>:
Dennis,

As alternative
If mycolor.ToArgb = mycolor.Empty.ToArgb

End if

Cor

"Dennis" <De****@discussions.microsoft.com>:

公共mycolor为color = color.Empty

我想检查一下是否用户指定了一种颜色;

如果mycolor = Color.Empty则.....

如果mycolor是Color.Empty则...... 。

我得到错误,说=可以用于颜色,不能用
值类型。我放弃了...我该怎么做。谢谢。
-
丹尼斯在休斯敦

public mycolor as color = color.Empty

I want to check to see if the user has specified a color like;

if mycolor = Color.Empty then.....
or
if mycolor is Color.Empty then .......

I get errors saying that = can be used for colors and is can''t be used
with
value types. I give up...how do I do this. Thanks.
--
Dennis in Houston



这篇关于比较空值类型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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