C# structures

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.
 
J

Jon Skeet [C# MVP]

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.
 
W

William Ryan

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();
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top