CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 7 of 7
  1. #1
    Join Date
    Apr 2005
    Posts
    159

    User defined types in CSharp

    Hi

    I created a project in VB6 and now converting it to CSharp
    In my vb6 project i defined a User defined type as below

    Code:
    Type Dated
             day     As String
             month   As String
             year    As String
    End Type
    Now i want to convert it to CSharp (i searched it on the web but helpless)

    How can i acomplish this in CSharp?

    any help will be appreciated a lot

  2. #2
    Join Date
    Jul 2008
    Location
    Germany
    Posts
    210

    Re: User defined types in CSharp

    Hi,

    there is no need for own type for date, just have a look on the DateTime class, which is much more powerful, as you think.

    Example
    Code:
    DateTime myDate = new DateTime(2008,11,11);

  3. #3
    Join Date
    Apr 2005
    Posts
    159

    Re: User defined types in CSharp

    Quote Originally Posted by MNovy View Post
    Hi,

    there is no need for own type for date, just have a look on the DateTime class, which is much more powerful, as you think.

    Example
    Code:
    DateTime myDate = new DateTime(2008,11,11);
    Thanks MNovy for suggestion but my emphases is user defined type conversion

  4. #4
    Join Date
    Jul 2001
    Location
    Sunny South Africa
    Posts
    11,284

    Re: User defined types in CSharp

    struct

  5. #5
    Join Date
    Mar 2004
    Location
    Prague, Czech Republic, EU
    Posts
    1,701

    Re: User defined types in CSharp

    Maybe. But why to have fields as string? Why not do it this way:
    Code:
    public struct Dated
    {
       public int day;
       public int month;   As String
       public int year;
    }
    But I have another question: does it make sence to have strings as members of a struct? More generally: does it make sence to have reference type as members of a struct?
    • Make it run.
    • Make it right.
    • Make it fast.

    Don't hesitate to rate my post.

  6. #6
    Join Date
    Apr 2005
    Posts
    159

    Re: User defined types in CSharp

    heartiest thanks for the help.

    Really it does not make any sense to define day,month,year as string.

    The code was just an example and your help made me capable to step ahead.

    Silly

  7. #7
    Join Date
    Mar 2002
    Location
    St. Petersburg, Florida, USA
    Posts
    12,125

    Re: User defined types in CSharp

    Be VERY aware of the differences between a struct and a class!!!!!!!!!!
    TheCPUWizard is a registered trademark, all rights reserved. (If this post was helpful, please RATE it!)
    2008, 2009,2010
    In theory, there is no difference between theory and practice; in practice there is.

    * Join the fight, refuse to respond to posts that contain code outside of [code] ... [/code] tags. See here for instructions
    * How NOT to post a question here
    * Of course you read this carefully before you posted
    * Need homework help? Read this first

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured