is this redundant...

Discussion in 'ASP .Net' started by =?Utf-8?B?cm9kY2hhcg==?=, Sep 16, 2005.

  1. hey all,

    Private Property mEmployeeDataset() As DsHRLIBR24
    Get
    Return DirectCast(Session("oDs"), DsHRLIBR24)
    End Get
    Set(ByVal Value As DsHRLIBR24)
    Session("oDs") = Value
    End Set
    End Property

    Is my DirectCast needed in this case?

    thanks,
    rodchar
     
    =?Utf-8?B?cm9kY2hhcg==?=, Sep 16, 2005
    #1
    1. Advertising

  2. =?Utf-8?B?cm9kY2hhcg==?=

    George Guest

    If you will be able to compile without it then no.

    I do not know much about VB.NET in C# you must you cast in cases like that.

    George.

    "rodchar" <> wrote in message news:...
    hey all,

    Private Property mEmployeeDataset() As DsHRLIBR24
    Get
    Return DirectCast(Session("oDs"), DsHRLIBR24)
    End Get
    Set(ByVal Value As DsHRLIBR24)
    Session("oDs") = Value
    End Set
    End Property

    Is my DirectCast needed in this case?

    thanks,
    rodchar
     
    George, Sep 16, 2005
    #2
    1. Advertising

  3. > Is my DirectCast needed in this case?

    Not needed, but certainly acceptable. And not redundant.

    The difference between CType and DirectCast is that CType will work as long
    as there is a valid conversion defined for the expression and the object
    type specified, whereas DirectCast will only work if the run-time types are
    the same. For example:

    Dim i As Integer = CType("23", Integer) 'Fine
    Dim i As Integer = DirectCast("23", Integer) ' Exception

    --
    HTH,

    Kevin Spencer
    Microsoft MVP
    ..Net Developer
    Neither a follower nor a lender be.

    "rodchar" <> wrote in message
    news:...
    > hey all,
    >
    > Private Property mEmployeeDataset() As DsHRLIBR24
    > Get
    > Return DirectCast(Session("oDs"), DsHRLIBR24)
    > End Get
    > Set(ByVal Value As DsHRLIBR24)
    > Session("oDs") = Value
    > End Set
    > End Property
    >
    > Is my DirectCast needed in this case?
    >
    > thanks,
    > rodchar
     
    Kevin Spencer, Sep 16, 2005
    #3
  4. thanks everyone for the help.

    "Kevin Spencer" wrote:

    > > Is my DirectCast needed in this case?

    >
    > Not needed, but certainly acceptable. And not redundant.
    >
    > The difference between CType and DirectCast is that CType will work as long
    > as there is a valid conversion defined for the expression and the object
    > type specified, whereas DirectCast will only work if the run-time types are
    > the same. For example:
    >
    > Dim i As Integer = CType("23", Integer) 'Fine
    > Dim i As Integer = DirectCast("23", Integer) ' Exception
    >
    > --
    > HTH,
    >
    > Kevin Spencer
    > Microsoft MVP
    > ..Net Developer
    > Neither a follower nor a lender be.
    >
    > "rodchar" <> wrote in message
    > news:...
    > > hey all,
    > >
    > > Private Property mEmployeeDataset() As DsHRLIBR24
    > > Get
    > > Return DirectCast(Session("oDs"), DsHRLIBR24)
    > > End Get
    > > Set(ByVal Value As DsHRLIBR24)
    > > Session("oDs") = Value
    > > End Set
    > > End Property
    > >
    > > Is my DirectCast needed in this case?
    > >
    > > thanks,
    > > rodchar

    >
    >
    >
     
    =?Utf-8?B?cm9kY2hhcg==?=, Sep 16, 2005
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Neil Zanella
    Replies:
    15
    Views:
    958
    Jim Wu
    Dec 18, 2003
  2. =?Utf-8?B?Sm9obiBXYWxrZXI=?=

    Redundant ASP.NET SQL command executions.

    =?Utf-8?B?Sm9obiBXYWxrZXI=?=, Oct 7, 2004, in forum: ASP .Net
    Replies:
    7
    Views:
    387
    Hermit Dave
    Oct 11, 2004
  3. JustAnotherGuy

    Redundant links

    JustAnotherGuy, Dec 28, 2003, in forum: HTML
    Replies:
    9
    Views:
    566
  4. Benjamin Rutt

    finding redundant #includes to shorten compile time

    Benjamin Rutt, Feb 5, 2004, in forum: C Programming
    Replies:
    15
    Views:
    1,053
    CBFalconer
    Feb 6, 2004
  5. Colin Kern

    Avoiding redundant functions

    Colin Kern, Apr 10, 2004, in forum: C Programming
    Replies:
    3
    Views:
    340
    Anthony Wong
    Apr 10, 2004
Loading...

Share This Page