C# structures

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hello
I'm trying to use a C# structure as follows.
class myclass
{
struct myStruct
{
int a;
int b;
}

myStruct S1 = new myStruct();
}
For some reasonI'm not able to access S1.a and S1.b from a
method within the same class.
Any help is much appreciated.
 
I'm trying to use a C# structure as follows.
class myclass
{
struct myStruct
{
int a;
int b;
}

myStruct S1 = new myStruct();
}
For some reasonI'm not able to access S1.a and S1.b from a
method within the same class.
Any help is much appreciated.

Fields are private by default - you'll need to declare them as internal
or public to be able to access them from your class.
 
change the access modifier of int a and int b to public and see if that
doesn't fix it. If you are in the same class/namespace, you should be good
to go and that's the case if you can create a new myStruct();
 
Back
Top