Question Defining a new structure from a structure inside a class

NorthMan

New member
Joined
Jan 19, 2013
Messages
3
Programming Experience
10+
Hi
I have declared a structure in side a class. I'm using it like a usertype within the class. Can I create a new structure outside of the class defined by the structure inside of the class. Something like this...

public class MyClass
public structure MyStructure
public k as integer
public v as integer
end structure
end class

public class AnotherClass

dim S as new MyClass.MyStructure

end class

Thanks.
 
Why not just try it and see if it works? You should always try what you can for yourself before posting. In this case, you can pretty much just put the code you posted here into a project and it will either work or it won't.

That said, why exactly is that structure declared inside a class to begin with? Structures are first-class types in .NET, just like classes. If you wouldn't declare a class inside a class then there's no reason to declare a structure inside a class. There are occasionally reasons to declare one type inside another but such cases are in the minority.
 
Well. I have been trying different versions of that code, but I get a not defined error. I'm using the structure in a user control class where I may have up to 200 instances of it in a array. I want to be able to move that array from one class to another. Creating a new structure in the new class from the control class would make it easier. I guess I could use a string for that but I'm thinking there may be a better way.
 
None of that really makes a great deal of sense. As I said in the first place, why not just declare the structure in its own code file, just like you do for a class? Then you can access it the same as you can a class. There is no reason to declare a structure inside a class unless there is some special relationship between the two, which it sounds like there isn't in this case.
 
Sorry for not making it clear. There is a special relationship between the two. I just have a hard time explaining it. I'll probably go with your advice and separate the structure and class though. Thank you, I really appreciate your help.
 
Back
Top