|
web
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Assigning Nullables to each othercorrect to assign _DeptID = Value like I would have if it was just a plain ole Integer, or is this like setting two objects equal to each other where the end result is that the one on the left now points to the same memory address as the one on the right? Should I instead be assigning _DeptID.Value = Value.Value or _DeptID.Value = CInt(Value.Value)? Public Property DeptID() As Nullable(Of Integer) Get Return _DeptID End Get Set(ByVal Value As Nullable(Of Integer)) If Not Value.Equals(_DeptID) Then _DeptID = Value _HasChanged = True End If End Set End Property ' DeptID >In my property declaration, shown below, is it Nullable(Of T) is a structure, so you'll store a copy of the value.>correct to assign _DeptID = Value like I would have if it was just a >plain ole Integer, or is this like setting two objects equal to each >other where the end result is that the one on the left now points to >the same memory address as the one on the right? Mattias -- Mattias Sjögren [C# MVP] mattias @ mvps.org http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com Please reply only to the newsgroup. Thanks Mattias...sounds like it's cool the way I'm doing it then.
Another question, if you don't mind... If I wanted to create a function, called let's say GetNullableIntFromIntField, which took as its input an integer field coming in from a DB (e.g. rdr("DeptID")) and gave back either Nothing or the integer value, what would the Function declaration look like? Function GetNullableIntFromIntField(ByVal oSomething As ???) As ??? If IsDBNull(oSomething) Then Return Nothing Else Return CInt(oSomething) End If End Function >what would the Function declaration look like? Function GetNullableIntFromIntField(ByVal oSomething As Object) As> > >Function GetNullableIntFromIntField(ByVal oSomething As ???) As ??? Nullable(Of Integer) or if you want to generalize it a bit Function GetNullableFromField(Of T As {Structure})(ByVal oSomething As Object) As Nullable(Of T) If IsDBNull(oSomething) Then Return Nothing Else Return CType(oSomething, T) End If End Function Mattias -- Mattias Sjögren [C# MVP] mattias @ mvps.org http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com Please reply only to the newsgroup. Mattias Sjögren wrote:
> >what would the Function declaration look like? This gives me an error message, in the editor environment stating> > > > > >Function GetNullableIntFromIntField(ByVal oSomething As ???) As ??? > > > Function GetNullableIntFromIntField(ByVal oSomething As Object) As > Nullable(Of Integer) > "Nullable is a type and cannot be used as an expression" > or if you want to generalize it a bit I like the idea of a general function, since I have to deal with Dates> > Function GetNullableFromField(Of T As {Structure})(ByVal oSomething As > Object) As Nullable(Of T) > If IsDBNull(oSomething) Then > Return Nothing > Else > Return CType(oSomething, T) > End If > End Function > and Booleans as well. However, I get error messages, when trying to Build, related to this one... Error 9 'Object' is a class type and cannot be used as an expression. In the editor environment it states, when I hover over the function name, "Function without an 'As' clause; return type of object assumed." >> Function GetNullableIntFromIntField(ByVal oSomething As Object) As Put it all on the same line (or use the _ line continuation>> Nullable(Of Integer) >> > >This gives me an error message, in the editor environment stating >"Nullable is a type and cannot be used as an expression" character). It's just broken up by my newsreader. It should be (if we shorten the names a bit) Function X(ByVal y As Object) As Nullable(Of Integer) Mattias -- Mattias Sjögren [C# MVP] mattias @ mvps.org http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com Please reply only to the newsgroup. Yup...that did it...was obviously up way too late copying and pasting
that code in...not paying attention to an obvious thing like that! Thanks...
Label Autosize Property... Possible bug??
Does vb.net winform supports checkbox groups? Writing a byte to a specific location in a file I don't get this --> Make Thread-Safe Calls to Windows Forms Controls Can Format function force upper/lower case? Exception.ToString() VB 2005 OOP Videos Wizard for UserControl Windows Service inpubox |
|||||||||||||||||||||||