|
-
May 21st, 2010, 11:19 PM
#1
About structs and arrays
Hi all. What does this mean?
Code:
public struct MyStruct
{
public int num;
public string name;
public double weight;
}
Public static MyStruct [] objstruct;
// Then in some method body, it is initialized on the heap as....
public void AnyMethod()
{
.....
.....
objstruct = new MyStruct[0]; // What does this declaration mean?
.....
.....
}
Earlier, I thought that this is some error where the size of array cannot be 0 and it should be at least 1 for the array to do something useful. But, on having second look, I thought that the object is being initialized on a single element of the struct array. But then, how does it iterate through the elements of the struct array.
Then, again one question comes to my mind is, there is no where the array is being initialized to a fixed length which is a necessity for C# arrays as far as I know. However, I know that C# arrays come under System.Array class and that allows a declaration as:
Code:
Array<MyStruct> objStruct = new Array<MyStruct>();
Also, can Resize() method provided by System.Array be used in similar situations where the size of the arrays is not known initially?
And, how can I get the count of the elements in a struct Array if it is a value type?
Also, how can I get the size of a struct in bytes? I know that sizeof operator can be used only with the simple data types or else...? I also found a SizeOf method that is provided by System.Runtime.InteropServices classes, but don't know how would I get the size of a managed struct (value type) using the same...
Thanks for any help in these issues
Bhushan
-
May 22nd, 2010, 01:38 PM
#2
Re: About structs and arrays
Any clues/comments from any one? Still waiting for any help...
Thanks
Bhushan
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|