Results 1 to 3 of 3

Thread: [RESOLVED] Convert Visual Basic User Type into C#??

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Aug 2005
    Location
    Wisconsin
    Posts
    788

    Resolved [RESOLVED] Convert Visual Basic User Type into C#??

    In Visual Basic 6 you can set up a user defined type and declare an array as that type. How does this get accomplished in C#? Do I create a dataset to hold the values I need? ArrayList?

    Code:
    Type TypeGLCash
        CshGLNo As String
        CshGLAmt As String
        CshTicket As String
    End Type
    
    Private GLCash() As TypeGLCash

  2. #2

    Thread Starter
    Fanatic Member
    Join Date
    Aug 2005
    Location
    Wisconsin
    Posts
    788

    Re: Convert Visual Basic User Type into C#??

    I have seen some information about structs. Can you create an struct array?

    Code:
            private struct YPUR
            {
                private string CustNum;
                private string CustName;
    
            }

  3. #3
    PowerPoster kfcSmitty's Avatar
    Join Date
    May 2005
    Posts
    2,248

    Re: Convert Visual Basic User Type into C#??

    To create that in C#, I would do the following:

    C# Code:
    1. public struct TypeGLCash
    2. {
    3.   public string cshGLNo;
    4.   public string cshGLAmt;
    5.   public string cshTicket;
    6. }

    And then create a list in your code like

    C# Code:
    1. List<TypeGLCash> list = new List<TypeGLCash>();

    You can then add an item to it as follows:

    C# Code:
    1. TypeGLCash newitem = new TypeGLCash();
    2. newitem.cshGLAmt = "1";
    3. newitem.cshGLNo = "2";
    4. newitem.cshTicket = "3";
    5.  
    6. list.Add(newitem);

    You can also create a constructor in the struct and add the item to the list in one line

    C# Code:
    1. public struct TypeGLCash
    2. {
    3.   public string cshGLNo;
    4.   public string cshGLAmt;
    5.   public string cshTicket;
    6.  
    7.   public TypeGLCash(string cshGLNo, string cshGLAmt, string cshTicket)
    8.   {
    9.     this.cshGLNo = cshGLNo;
    10.     this.cshGLAmt = cshGLAmt;
    11.     this.cshTicket = cshTicket;
    12.   } //end TypeGLCash
    13. }
    14.  
    15. //and create the list/add an item
    16. List<TypeGLCash> list = new List<TypeGLCash>();
    17. list.Add(new TypeGLCash("1", "2", "3"));
    Last edited by kfcSmitty; Nov 29th, 2012 at 04:02 PM.

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