Click here to Skip to main content
15,913,854 members
Home / Discussions / C#
   

C#

 
GeneralRe: Erasing lines Pin
CoolASL26-Mar-06 23:04
CoolASL26-Mar-06 23:04 
QuestionHow can i bind two controls together in witch that when one control scrolls the other scrolls too? Pin
Bobby88725-Mar-06 6:06
Bobby88725-Mar-06 6:06 
AnswerRe: How can i bind two controls together in witch that when one control scrolls the other scrolls too? Pin
Ravi Bhavnani25-Mar-06 8:09
professionalRavi Bhavnani25-Mar-06 8:09 
QuestionWindows Service Pin
hung_ngole25-Mar-06 6:04
hung_ngole25-Mar-06 6:04 
QuestionDrawing a line in ASP.NET Pin
naglbitur25-Mar-06 5:00
naglbitur25-Mar-06 5:00 
AnswerRe: Drawing a line in ASP.NET Pin
leppie25-Mar-06 6:51
leppie25-Mar-06 6:51 
AnswerRe: Drawing a line in ASP.NET Pin
Guffa25-Mar-06 7:18
Guffa25-Mar-06 7:18 
QuestionCorrection: How to define an array in a class Pin
IceWater4225-Mar-06 4:54
IceWater4225-Mar-06 4:54 
Hi ...

I corrected my original post. I hope someone can help me with what should be a simple problem.
-------------------------------------------------------

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.


AnswerRe: Correction: How to define an array in a class Pin
Nicholas Butler25-Mar-06 5:26
sitebuilderNicholas Butler25-Mar-06 5:26 
GeneralRe: Correction: How to define an array in a class Pin
IceWater4225-Mar-06 6:49
IceWater4225-Mar-06 6:49 
GeneralRe: Correction: How to define an array in a class Pin
Guffa25-Mar-06 7:21
Guffa25-Mar-06 7:21 
QuestionMicrosoft Office Spreadsheet 10.0 Pin
i_martin_r25-Mar-06 4:45
i_martin_r25-Mar-06 4:45 
AnswerRe: Microsoft Office Spreadsheet 10.0 Pin
mcljava25-Mar-06 12:36
mcljava25-Mar-06 12:36 
QuestionDrag and drop Pin
valiovalio25-Mar-06 4:32
valiovalio25-Mar-06 4:32 
AnswerRe: Drag and drop Pin
Robert Rohde25-Mar-06 7:40
Robert Rohde25-Mar-06 7:40 
GeneralRe: Drag and drop Pin
valiovalio25-Mar-06 9:36
valiovalio25-Mar-06 9:36 
QuestionShortcut Pin
nogola25-Mar-06 4:07
nogola25-Mar-06 4:07 
QuestionRemoting or Sockets??? Pin
RizwanSharp25-Mar-06 4:05
RizwanSharp25-Mar-06 4:05 
QuestionSend Message to IM Window Pin
RizwanSharp25-Mar-06 3:57
RizwanSharp25-Mar-06 3:57 
QuestionDetect Opened Forms Pin
RizwanSharp25-Mar-06 3:49
RizwanSharp25-Mar-06 3:49 
AnswerRe: Detect Opened Forms Pin
Stefan Troschuetz25-Mar-06 4:02
Stefan Troschuetz25-Mar-06 4:02 
GeneralRe: Detect Opened Forms Pin
RizwanSharp25-Mar-06 4:09
RizwanSharp25-Mar-06 4:09 
GeneralRe: Detect Opened Forms Pin
Stefan Troschuetz25-Mar-06 4:17
Stefan Troschuetz25-Mar-06 4:17 
GeneralRe: Detect Opened Forms Pin
RizwanSharp25-Mar-06 4:23
RizwanSharp25-Mar-06 4:23 
GeneralRe: Detect Opened Forms Pin
mav.northwind25-Mar-06 4:18
mav.northwind25-Mar-06 4:18 

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.