Click here to Skip to main content
15,887,027 members
Home / Discussions / C#
   

C#

 
GeneralRe: Deployment project: adding uninstall icon Pin
Heath Stewart4-Feb-04 5:29
protectorHeath Stewart4-Feb-04 5:29 
GeneralRe: Deployment project: adding uninstall icon Pin
Radoslav Bielik4-Feb-04 20:58
Radoslav Bielik4-Feb-04 20:58 
GeneralRe: Deployment project: adding uninstall icon Pin
Heath Stewart5-Feb-04 4:14
protectorHeath Stewart5-Feb-04 4:14 
GeneralProblem with arrays... Pin
Andres Coder3-Feb-04 21:46
Andres Coder3-Feb-04 21:46 
GeneralRe: Problem with arrays... Pin
Radoslav Bielik3-Feb-04 21:54
Radoslav Bielik3-Feb-04 21:54 
GeneralRe: Problem with arrays... Pin
Andres Coder4-Feb-04 3:29
Andres Coder4-Feb-04 3:29 
GeneralRe: Problem with arrays... Pin
Andres Coder4-Feb-04 3:29
Andres Coder4-Feb-04 3:29 
GeneralRe: Problem with arrays... Pin
Heath Stewart4-Feb-04 3:53
protectorHeath Stewart4-Feb-04 3:53 
The previous post isn't correct.

When you instantiate an array, the elements Types of that array are not instantiated. All you have is an array of your Type, in which the array is derived by the CLR from System.Array. In order to instantiate each element in the array, you must do so by iterating through each element:
public SomeInfo[] SomeArray = new SomeInfo[3];
for (int i=0; i<SomeArray.Length; i++)
  SomeArray[i] = new SomeArray();
If you want to make your struct easier to use, you can add a constructor that takes params of the Types you need for your members. The only restriction when declaring constructors is that - for structs - you cannot declare the default constructor (parameterless constructor):
public struct SomeInfo
{
  public SomeInfo(string value1, int value2, SomeClass value3)
  {
    this.Value1 = value1;
    this.Value2 = value2;
    this.Value3 = value3;
  }
  public string Value1;
  public int Value2;
  public SomeClass Value3;
}
Then you can either instantiate a default instance (all member types use their default values and reference members (like Value3) are null) or an initialized struct when you're looping through (assuming you had a source you could iterate through and pull values from):
string[] names = {"One", "Two", "Three"};
SomeClass theOneInstance = new SomeClass();
SomeInfo[] SomeArray = new SomeInfo[3];
for (int i=0; i<SomeArray.Length; i++)
  SomeArray[i] = new SomeInfo(names[i], i, theOneInstance);


 

Microsoft MVP, Visual C#
My Articles
GeneralRe: Problem with arrays... Pin
Andres Coder4-Feb-04 23:14
Andres Coder4-Feb-04 23:14 
GeneralRe: Problem with arrays... Pin
Jeff Varszegi12-Mar-04 9:00
professionalJeff Varszegi12-Mar-04 9:00 
QuestionRecord types in C# ? Pin
Andres Coder3-Feb-04 19:59
Andres Coder3-Feb-04 19:59 
AnswerRe: Record types in C# ? Pin
John Kuhn3-Feb-04 20:18
John Kuhn3-Feb-04 20:18 
GeneralRe: Record types in C# ? Pin
Heath Stewart3-Feb-04 20:37
protectorHeath Stewart3-Feb-04 20:37 
GeneralRe: Record types in C# ? Pin
John Kuhn3-Feb-04 20:43
John Kuhn3-Feb-04 20:43 
GeneralRe: Record types in C# ? Pin
Andres Coder3-Feb-04 20:45
Andres Coder3-Feb-04 20:45 
GeneralRe: Record types in C# ? Pin
Heath Stewart4-Feb-04 3:29
protectorHeath Stewart4-Feb-04 3:29 
AnswerRe: Record types in C# ? Pin
Heath Stewart3-Feb-04 20:32
protectorHeath Stewart3-Feb-04 20:32 
GeneralRe: Record types in C# ? Pin
Andres Coder3-Feb-04 20:48
Andres Coder3-Feb-04 20:48 
Generalkernel process on c# Pin
laurentz_wei3-Feb-04 18:36
laurentz_wei3-Feb-04 18:36 
GeneralRe: kernel process on c# Pin
Heath Stewart3-Feb-04 20:21
protectorHeath Stewart3-Feb-04 20:21 
GeneralRe: kernel process on c# Pin
Mazdak3-Feb-04 20:24
Mazdak3-Feb-04 20:24 
GeneralOn Virtual And Override Pin
GetOn&GetGoing3-Feb-04 17:13
GetOn&GetGoing3-Feb-04 17:13 
GeneralRe: On Virtual And Override Pin
TigerNinja_3-Feb-04 17:38
TigerNinja_3-Feb-04 17:38 
GeneralRe: On Virtual And Override Pin
Heath Stewart3-Feb-04 20:18
protectorHeath Stewart3-Feb-04 20:18 
QuestionScrollBar bug? Pin
Meysam Mahfouzi3-Feb-04 16:58
Meysam Mahfouzi3-Feb-04 16:58 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.