VB.NET中没有布尔对象?如何检查是否已明确定义布尔值?

编程入门 行业动态 更新时间:2024-10-26 18:26:24
本文介绍了VB.NET中没有布尔对象?如何检查是否已明确定义布尔值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

例如在java中,有一种方法可以使用布尔值作为对象而不是 值类型。 我想要在VB.NET中做同样的事情,这样我就可以检查布尔值是否已明确定义(不是Nothing)。 但布尔值是VB中的结构。 NET(默认情况下定义为False)而不是一个对象所以我担心没有任何方法可以做任何我想做的事情而没有任何 的解决方法。 br /> 你能否确认VB.NET中没有布尔对象版本? 谢谢 Henri

推荐答案

" Henri" < HM ******** @ hotmail>写在 新闻:un ************** @ TK2MSFTNGP12.phx.gbl: "Henri" <hm********@hotmail> wrote in news:un**************@TK2MSFTNGP12.phx.gbl: 例如在java中,有一种方法可以使用布尔值作为对象,而不是作为值类型。我想在VB.NET中做同样的事情,以便我可以检查是否 boolean已明确定义(不是Nothing)。但是Boolean是VB.NET中的一个结构(默认定义为False)并且不是Object所以我担心没有没有任何解决方法可以做我想做的事。你能否确认VB.NET中没有布尔对象版本? In java for instance there''s a way to use booleans as objects and not as value types. I would like to do the same in VB.NET so that I can check if the boolean has been explicitely defined (is not Nothing). But Boolean is a Structure in VB.NET (defined to False by default) and not an Object so I''m afraid there''s no way to do what I want without any workaround. Can you confirm that there''s no object version of Boolean in VB.NET?

Nope,我不相信有一个布尔对象。 你应该有办法做你想做的事,因为 百万.NET开发人员不使用布尔对象; ) - Lucas Tam(RE********@rogers) 请删除[移除"来自回复时的电子邮件地址。 http://成员。 ebay/aboutme/coolspot18/

你不能只是制作一个包含公共财产的课程并且有一个 private布尔字段?私有布尔字段的值确定公共财产的价值是什么?b $ b?如果私有字段值没有设置,那么公共属性值保持默认值(您设置为 类构造函数中没有任何内容)。 " Henri" < HM ******** @ hotmail>在消息中写道 news:un **************** @ TK2MSFTNGP12.phx.gbl ... Couldn''t you just make a class that contains a public property and has a private Boolean field? The value of the private Boolean field determines the value of the public property? If the private field value hasn''t been set, then the public property value stays at its default (which you set to Nothing in the class constructor). "Henri" <hm********@hotmail> wrote in message news:un****************@TK2MSFTNGP12.phx.gbl... 在java中,例如,有一种方法可以使用布尔值作为对象,而不是使用值类型。我想在VB.NET中做同样的事情,这样我就可以检查布尔值是否为/>已明确定义(不是什么)。但布尔是VB.NET中的结构(默认定义为False)而不是对象所以我害怕没有任何解决方法就没办法做我想做的事。你能否确认VB.NET中没有布尔对象版本?谢谢 亨利 In java for instance there''s a way to use booleans as objects and not as value types. I would like to do the same in VB.NET so that I can check if the boolean has been explicitely defined (is not Nothing). But Boolean is a Structure in VB.NET (defined to False by default) and not an Object so I''m afraid there''s no way to do what I want without any workaround. Can you confirm that there''s no object version of Boolean in VB.NET? Thanks Henri

" Henri" < HM ******** @ hotmail>在消息中写道 news:un **************** @ TK2MSFTNGP12.phx.gbl ... : :在java中,例如,有一种方法可以使用布尔值作为对象而不是 :作为值类型。 :我想做在VB.NET中也一样,这样我就可以检查 :boolean是否已明确定义(不是Nothing)。 :但布尔值是VB中的结构。 NET(默认定义为False)和 :不是对象,所以我担心没有办法做我想要的事情 :任何解决方法。 :你能否确认VB.NET中没有布尔对象版本? :谢谢 : :Henri 也许你可以沿着这些线''''''布尔类型: Dim BooleanObj As Object = New Boolean 例如: ---------------------------- ----------------------- Option Strict 进口系统 Pub lic class [class] Public Shared Sub Main ''输出" True" Dim BooleanObj As Object Console.Writeline(BooleanObj什么都不是) ''输出" False" BooleanObj =新布尔值 Console.Writeline(BooleanObj什么都不是) ''输出" False" Console.WriteLine(BooleanObj) ''输出" True" BooleanObj = True Console.WriteLine(BooleanObj) 结束SUb 结束班级 ------------------------------ --------------------- 如果您愿意,可以自己编写课程: - -------------------------------------------------- Public Class BooleanObj Private b As Boolean Public Sub New End Sub Public Sub New(价值为布尔值) b =价值 结束子 酒吧lic属性值()作为布尔值 获取 返回b 结束获取 设置 b = value 结束集 结束属性 公共覆盖函数ToString()As String 返回b.toString 结束函数 公共覆盖重载函数等于(obj为对象)为布尔值 如果obj什么都没有那么 返回错误 结束如果 如果不是Me.GetType()是obj。 GetType()然后 返回False 结束如果 Dim o As BooleanObj = CType(obj,BooleanObj) 如果b<> ob然后 返回错误 结束IF 返回真实 结束功能 结束课 ---------------------------- ----------------------- Ralf "Henri" <hm********@hotmail> wrote in message news:un****************@TK2MSFTNGP12.phx.gbl... : : In java for instance there''s a way to use booleans as objects and not : as value types. : I would like to do the same in VB.NET so that I can check if the : boolean has been explicitely defined (is not Nothing). : But Boolean is a Structure in VB.NET (defined to False by default) and : not an Object so I''m afraid there''s no way to do what I want without : any workaround. : Can you confirm that there''s no object version of Boolean in VB.NET? : Thanks : : Henri Perhaps you could ''box'' the boolean type along these lines: Dim BooleanObj As Object = New Boolean For Example: --------------------------------------------------- Option Strict Imports System Public Class [class] Public Shared Sub Main ''Outputs "True" Dim BooleanObj As Object Console.Writeline(BooleanObj Is Nothing) ''Outputs "False" BooleanObj = New Boolean Console.Writeline(BooleanObj Is Nothing) ''Outputs "False" Console.WriteLine(BooleanObj) ''Outputs "True" BooleanObj = True Console.WriteLine(BooleanObj) End SUb End Class --------------------------------------------------- Or if you prefer, you can write your own class: --------------------------------------------------- Public Class BooleanObj Private b As Boolean Public Sub New End Sub Public Sub New(Value As Boolean) b = Value End Sub Public Property Value() As Boolean Get Return b End Get Set b = value End Set End Property Public Overrides Function ToString() As String Return b.toString End Function Public Overrides Overloads Function Equals(obj As Object) As Boolean If obj Is Nothing Then Return False End If If Not Me.GetType() Is obj.GetType() Then Return False End If Dim o As BooleanObj = CType(obj, BooleanObj) If b <> o.b Then Return False End IF Return True End Function End Class --------------------------------------------------- Ralf

更多推荐

VB.NET中没有布尔对象?如何检查是否已明确定义布尔值?

本文发布于:2023-11-05 15:46:49,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1561241.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:布尔   定义   对象   布尔值   VB

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!