Hi all. What does this 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.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?
.....
.....
}
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:
Also, can Resize() method provided by System.Array be used in similar situations where the size of the arrays is not known initially?Code:Array<MyStruct> objStruct = new Array<MyStruct>();
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
