Click here to Skip to main content
15,891,657 members
Home / Discussions / C#
   

C#

 
GeneralRe: Sending email using c# Pin
YAI10-Apr-08 18:31
YAI10-Apr-08 18:31 
GeneralRe: Sending email using c# Pin
#realJSOP11-Apr-08 4:20
mve#realJSOP11-Apr-08 4:20 
GeneralRe: Sending email using c# Pin
Abhijit Jana10-Apr-08 18:26
professionalAbhijit Jana10-Apr-08 18:26 
GeneralRe: Sending email using c# Pin
YAI17-Apr-08 18:03
YAI17-Apr-08 18:03 
GeneralPrintPreviewDialog printer selection. Pin
msx2310-Apr-08 12:54
msx2310-Apr-08 12:54 
GeneralRe: PrintPreviewDialog printer selection. Pin
Luc Pattyn10-Apr-08 13:50
sitebuilderLuc Pattyn10-Apr-08 13:50 
GeneralAnoying add-in, context menu, problem... Pin
Kasic Slobodan10-Apr-08 12:16
Kasic Slobodan10-Apr-08 12:16 
GeneralSimple C# array of classes question? (C# vs C++ ) Pin
Pinhead_Me10-Apr-08 10:25
Pinhead_Me10-Apr-08 10:25 
Hi,

I must be missing something very basic so please excuse the seemingly simplicity of this question:

Question: How does one create an array of classes in C# without having to call the constructor for each elment in the array.

Example: In C++ one would do the following:

<br />
class MyClass<br />
{<br />
  public:<br />
    int myData;<br />
<br />
    MyClass::MyClass()<br />
    {<br />
       myData= 1;<br />
    }<br />
};<br />


In main:

void main()<br />
{<br />
<br />
    MyClass myVar[12];<br />
<br />
   cout << myVar[0].myData; //result prints '1'<br />
}<br />


For C# I try this (ignore any syntax errors that may exists):

<br />
void Main()<br />
{<br />
<br />
MyClass[] myVar = new MyClass[12];<br />
<br />
 Console.WriteLine("{0}", myVar[0].myData); // Exception thrown, null reference<br />
<br />
}

Can this be done in C#, if so, how?

-Joe
GeneralRe: Simple C# array of classes question? (C# vs C++ ) Pin
Luc Pattyn10-Apr-08 10:51
sitebuilderLuc Pattyn10-Apr-08 10:51 
GeneralRe: Simple C# array of classes question? (C# vs C++ ) Pin
Guffa10-Apr-08 16:39
Guffa10-Apr-08 16:39 
GeneralRe: Simple C# array of classes question? (C# vs C++ ) Pin
#realJSOP11-Apr-08 4:41
mve#realJSOP11-Apr-08 4:41 
GeneralRe: Simple C# array of classes question? (C# vs C++ ) Pin
Guffa11-Apr-08 11:13
Guffa11-Apr-08 11:13 
GeneralRe: Simple C# array of classes question? (C# vs C++ ) Pin
Pinhead_Me11-Apr-08 18:56
Pinhead_Me11-Apr-08 18:56 
GeneralRe: Simple C# array of classes question? (C# vs C++ ) Pin
Guffa12-Apr-08 14:15
Guffa12-Apr-08 14:15 
Generalinterpret address locations Pin
shwaguy10-Apr-08 10:25
shwaguy10-Apr-08 10:25 
GeneralRe: interpret address locations Pin
pmarfleet10-Apr-08 10:56
pmarfleet10-Apr-08 10:56 
GeneralRe: interpret address locations Pin
shwaguy28-Apr-08 4:44
shwaguy28-Apr-08 4:44 
GeneralSub Form Pin
rockNroll10-Apr-08 10:22
rockNroll10-Apr-08 10:22 
GeneralRe: Sub Form Pin
Luc Pattyn10-Apr-08 10:55
sitebuilderLuc Pattyn10-Apr-08 10:55 
GeneralDataGridView binding Pin
Shekelele10-Apr-08 9:54
Shekelele10-Apr-08 9:54 
GeneralRe: DataGridView binding Pin
sarilee10-Apr-08 21:09
sarilee10-Apr-08 21:09 
GeneralRe: DataGridView binding Pin
Shekelele11-Apr-08 4:24
Shekelele11-Apr-08 4:24 
QuestionVideo motion detection and cursor movement Pin
=Momi=10-Apr-08 9:52
=Momi=10-Apr-08 9:52 
GeneralRe: Video motion detection and cursor movement Pin
Christian Graus10-Apr-08 13:00
protectorChristian Graus10-Apr-08 13:00 
QuestionBitmap + Clipboard + Transparency = Blue Background? Pin
Chadwick Posey10-Apr-08 9:49
Chadwick Posey10-Apr-08 9:49 

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.