I have the need to create a struct that will only be usefull inside a method. I have been trying to do so by doing something like this:
public class myClass
{
public void myMethod
{
private struct myStruct
{ int myInt; }
}
}
I a keep getting compiler errors such as:
} expected
Can somebody give me any clue on this?
Thanks in advance!
LAMScoping a struct to a method isn't allowed. You can scope a struct to a class, though, using the private keyword and embedding it inside a class.
public class MyClass
{
private struct MyStruct { int MyInt; }
public void MyMethod()
{
MyStruct x = new MyStruct();
}
}
This should work perfectly fine.
Nick
0 comments:
Post a Comment