nested types

  • Thread starter Thread starter Wndr
  • Start date Start date
W

Wndr

Hi Guys.
I need to declare an array of PortType in MainType.
Does any one has idea on how to do that?
Any help apreciated.

public struct PortType
{
public string Description;
public int Port;
}

public struct MainType
{
public string Name;
//this part has a problem, I want to declare it inside of this
type, but when I want to use it, there is no ref to Ports from Main.
public static PortType[] Ports = new PortType[999];
}

public static MainType[] Main = new MainType[100];


So is there any way to use like this:
Main.Ports[x].Description="text";
 
Thank you for replay.
I am new in C#, that's why I called it static, sorry about that, what I
should change it to?
Peter Duniho said:
[...]
public struct MainType
{
public string Name;
//this part has a problem, I want to declare it inside of
this
type, but when I want to use it, there is no ref to Ports from Main.
public static PortType[] Ports = new PortType[999];
}

public static MainType[] Main = new MainType[100];


So is there any way to use like this:
Main.Ports[x].Description="text";


Not if you make the field "static". But if it's an instance member, then
it should work just as you seem to want it to.

Why did you mark it "static" if you want it to be an instance member?

Pete
 
Yes you know in VB it was prity simple,
I just had to declare
Public Type PortType
Description As String
Port As Integer
End Type

Public Type MainType
Name As String
Ports() As PortType
End Type


Public Main() As MainType
and then I could use:
Main(Index).Ports(i ).Description ="Test"
So I was trying to do like this in C#, everything worked fine until I got
to this point, it's not int, or string, or array, I was looking for this
info in books and on the web, but still coun't find it.
Thanks anyway.
 
Back
Top