[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
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;
}
Re: Convert Visual Basic User Type into C#??
To create that in C#, I would do the following:
C# Code:
public struct TypeGLCash
{
public string cshGLNo;
public string cshGLAmt;
public string cshTicket;
}
And then create a list in your code like
C# Code:
List<TypeGLCash> list = new List<TypeGLCash>();
You can then add an item to it as follows:
C# Code:
TypeGLCash newitem = new TypeGLCash();
newitem.cshGLAmt = "1";
newitem.cshGLNo = "2";
newitem.cshTicket = "3";
list.Add(newitem);
You can also create a constructor in the struct and add the item to the list in one line
C# Code:
public struct TypeGLCash
{
public string cshGLNo;
public string cshGLAmt;
public string cshTicket;
public TypeGLCash(string cshGLNo, string cshGLAmt, string cshTicket)
{
this.cshGLNo = cshGLNo;
this.cshGLAmt = cshGLAmt;
this.cshTicket = cshTicket;
} //end TypeGLCash
}
//and create the list/add an item
List<TypeGLCash> list = new List<TypeGLCash>();
list.Add(new TypeGLCash("1", "2", "3"));