Click here to Skip to main content
15,922,015 members
Home / Discussions / C#
   

C#

 
QuestionPerformanceCounter won't work Pin
polisen25-Mar-06 1:05
polisen25-Mar-06 1:05 
Questionlistview and image Pin
yosba22125-Mar-06 0:00
yosba22125-Mar-06 0:00 
QuestionVoice chat Pin
deepthi wilson24-Mar-06 23:45
deepthi wilson24-Mar-06 23:45 
AnswerRe: Voice chat Pin
RizwanSharp25-Mar-06 4:29
RizwanSharp25-Mar-06 4:29 
GeneralRe: Voice chat Pin
deepthi wilson26-Mar-06 17:06
deepthi wilson26-Mar-06 17:06 
QuestionHow do I list Drive informations of a remote computer Pin
deepthi wilson24-Mar-06 23:39
deepthi wilson24-Mar-06 23:39 
AnswerRe: How do I list Drive informations of a remote computer Pin
RizwanSharp25-Mar-06 3:29
RizwanSharp25-Mar-06 3:29 
QuestionArrays in a class definition Pin
IceWater4224-Mar-06 23:28
IceWater4224-Mar-06 23:28 
Hi ...

I'm having trouble setting the values of the array in my class.

I tried this ... and i can set/get "x.name" but pgm crashes with an error message that says i do not have an instance of the array item when i try to set "x.number[1]".

namespace WindowsApplication1
{
public partial class Form1 : Form
{
class myClass
{
// fields
private string _name;
private double[] _number;

// properties
public string name
{
get { return _name; }
set { _name = value; }
}

public double[] number;
public double this[int index]
{
get { return _number[index]; }
set { _number[index] = value; }
}

// Default constructor:
public myClass()
{
name = "";
double[] number = new double[5];
number[0] = 0;
number[1] = 0;
number[2] = 0;
number[3] = 0;
number[4] = 0;
}
// Clear Numbers
public void ClearNumbers()
{
double[] number = new double[5];
number[0] = 0;
number[1] = 0;
number[2] = 0;
number[3] = 0;
number[4] = 0;
}
}
public Form1()
{
InitializeComponent();
}

private void Form1_Load(object sender, EventArgs e)
{

}

private void button1_Click(object sender, EventArgs e)
{
myClass x = new myClass();
x.name = "Charlie";
x.number[1] = 123.45;
}
}
}

My program works on x.name = "Charlie";
My program fails on x.number[1] = 123.45;


Please advise on how to fix my class definition to accomodate arrays.

Thank you.


-- modified at 10:17 Saturday 25th March, 2006
AnswerRe: Arrays in a class definition Pin
Guffa25-Mar-06 0:21
Guffa25-Mar-06 0:21 
GeneralRe: Arrays in a class definition Pin
IceWater4225-Mar-06 4:30
IceWater4225-Mar-06 4:30 
GeneralRe: Arrays in a class definition Pin
kasik25-Mar-06 6:37
kasik25-Mar-06 6:37 
GeneralRe: Arrays in a class definition Pin
IceWater426-Apr-06 19:18
IceWater426-Apr-06 19:18 
GeneralRe: Arrays in a class definition Pin
kasik7-Apr-06 5:51
kasik7-Apr-06 5:51 
QuestionDial a number using C# Pin
mrkeivan24-Mar-06 23:12
mrkeivan24-Mar-06 23:12 
QuestionDirectSound & Speakers Pin
Superwill24-Mar-06 23:00
Superwill24-Mar-06 23:00 
Questionhow to use constructors?? Pin
abdelhameed8124-Mar-06 22:56
abdelhameed8124-Mar-06 22:56 
AnswerRe: how to use constructors?? Pin
Colin Angus Mackay25-Mar-06 0:06
Colin Angus Mackay25-Mar-06 0:06 
GeneralRe: how to use constructors?? Pin
Guffa25-Mar-06 0:58
Guffa25-Mar-06 0:58 
AnswerRe: how to use constructors?? Pin
Guffa25-Mar-06 0:55
Guffa25-Mar-06 0:55 
QuestionTAPI Pin
hafz24-Mar-06 21:39
hafz24-Mar-06 21:39 
Answercan you help me out Pin
mrkeivan25-Mar-06 0:34
mrkeivan25-Mar-06 0:34 
GeneralRe: can you help me out Pin
RizwanSharp25-Mar-06 3:09
RizwanSharp25-Mar-06 3:09 
GeneralRe: can you help me out Pin
cfsego7-May-06 21:05
cfsego7-May-06 21:05 
GeneralRe: can you help me out Pin
mrkeivan8-May-06 3:58
mrkeivan8-May-06 3:58 
QuestionCan We detect Sql Servers on Network using c# Pin
Jax_qqq24-Mar-06 19:37
Jax_qqq24-Mar-06 19:37 

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.