Jump to content
  • Advertisement
Sign in to follow this  
V-man

Array in a structure. Visual Basic .NET

This topic is 2807 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi,I'm totally new to VB.NET.
I would like to have an array in a structure in VB.NET just like we do in C++


struct MyThing
{
uchar color[4];
}


but it seems as if you can't have an array in VB.NET inside a structure?

Share this post


Link to post
Share on other sites
Advertisement

Hi,I'm totally new to VB.NET.
I would like to have an array in a structure in VB.NET just like we do in C++


struct MyThing
{
uchar color[4];
}


but it seems as if you can't have an array in VB.NET inside a structure?


Keep in mind that a struct in C++ is pretty much the same thing as a class, whereas in .NET a structure is a value type, stored on the stack and a class is a reference type. Honestly, you're probably better off doing:

Public Class MyThing
Public color() as Char = Nothing

Public Sub New()
ReDim color(4)
End Sub
End Class



That should achieve the same goal. Edited by Tape_Worm

Share this post


Link to post
Share on other sites
But that is a pain in the but. I am converting code to VB.NET (don't ask me why, it's not my choice).
I would have to track down all the places that need a New() call.

There must be a better way.

Share this post


Link to post
Share on other sites
You can store arrays in VB.NET's structures (the same way as you declare arrays anywhere else, as demonstrated by Tape_Worm), but cannot easily set a fixed size as you would in C.

A better way would likely be to use the Color structure in place of the array.

Share this post


Link to post
Share on other sites
I don't understand your question; the Color structure he linked to does have R, G, B and A components.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!