Click here to Skip to main content
15,896,557 members
Home / Discussions / C#
   

C#

 
GeneralRe: Can't make array class data shown in a label Pin
Albert8324-Jan-06 9:41
Albert8324-Jan-06 9:41 
AnswerRe: Can't make array class data shown in a label Pin
Garry Stewart23-Jan-06 21:21
Garry Stewart23-Jan-06 21:21 
GeneralRe: Can't make array class data shown in a label Pin
Albert8324-Jan-06 9:51
Albert8324-Jan-06 9:51 
GeneralRe: Can't make array class data shown in a label Pin
Garry Stewart24-Jan-06 12:54
Garry Stewart24-Jan-06 12:54 
GeneralRe: Can't make array class data shown in a label Pin
Albert8324-Jan-06 19:32
Albert8324-Jan-06 19:32 
GeneralPlease disregard the previous exception in the previous message Pin
Albert8324-Jan-06 20:01
Albert8324-Jan-06 20:01 
GeneralRe: Please disregard the previous exception in the previous message Pin
Garry Stewart24-Jan-06 21:07
Garry Stewart24-Jan-06 21:07 
GeneralRe: Please disregard the previous exception in the previous message Pin
Albert8325-Jan-06 15:11
Albert8325-Jan-06 15:11 
Hi Garry, I still can't make it work. I change the code to the one below. And I got this exception: An unhandled exception of type 'System.NullReferenceException' occurred in WindowsApplication1.exe

Additional information: Object reference not set to an instance of an object.
:
It points to: person[0].Age = 22; - It all the way on the bottom. I tried so many different things, including putting all the class data in a different file. But first, I got the same exception as above, and second, the class didn't see the label. Thanks again for the help.
public class Person
{
//My instance variables

private string firstName, lastName;
private int age;
private double height, weight;
private string bankName;
private double bankAccount;
private double balance = 0;
private string squareColor;

//Properties
public string FirstName
{
get { return firstName; }
set { firstName = value; }
}
public string LastName
{
get { return lastName; }
set { lastName = value; }
}
public int Age
{
get { return age; }
set { age = value; }
}
public double Height1
{
get { return height; }
set { height = value; }
}
public double Weight
{
get { return weight; }
set { weight = value; }
}
public string BankName
{
get { return bankName; }
set { bankName = value; }
}
public double BankAccount
{
get { return bankAccount; }
set { bankAccount = value; }
}
public double Balance
{
get { return balance ; }
set { balance = value; }
}
public string SquareColor
{
get { return squareColor ; }
set { squareColor = value; }
}

//Custom constructor
public Person(int age, double height, double weight, string bankName, double bankAccount, double balance)
{
this.age = age;
this.height = height;
this.weight = weight;
this.bankName = bankName;
this.bankAccount = bankAccount;
this.balance = balance;
}
//Default constructor
public Person()
{
}
//My Methods
public void makeDeposit(int amount)
{
balance+= amount;
}
public void makeWithdrawal(int amount)
{
balance-= amount;
}
}
///
/// Summary description for Form1.
///

public class Form1 : System.Windows.Forms.Form
{
private System.Windows.Forms.Label label1;
private System.ComponentModel.Container components = null;

public Form1()
{
InitializeComponent();
}

protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}

#region Windows Form Designer generated code
///
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
///

private void InitializeComponent()
{
this.label1 = new System.Windows.Forms.Label();
this.SuspendLayout();
//
// label1
//
this.label1.Location = new System.Drawing.Point(32, 24);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(216, 184);
this.label1.TabIndex = 0;
this.label1.Text = "label1";
//
// Form1
//
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
this.ClientSize = new System.Drawing.Size(292, 266);
this.Controls.Add(this.label1);
this.Name = "Form1";
this.Text = "Form1";
this.ResumeLayout(false);

}
#endregion
}
public class Test
{
[STAThread]
static void Main()
{
Application.Run(new Form1());
Person[] person = new Person[3];
person[0].Age = 22;
}
};
}
GeneralRe: Can't make array class data shown in a label Pin
Albert8325-Jan-06 16:30
Albert8325-Jan-06 16:30 
GeneralRe: Can't make array class data shown in a label Pin
Garry Stewart25-Jan-06 16:39
Garry Stewart25-Jan-06 16:39 
GeneralRe: Can't make array class data shown in a label Pin
Albert8325-Jan-06 16:39
Albert8325-Jan-06 16:39 
GeneralRe: Can't make array class data shown in a label Pin
Albert8325-Jan-06 16:48
Albert8325-Jan-06 16:48 
GeneralRe: Can't make array class data shown in a label Pin
Garry Stewart25-Jan-06 16:59
Garry Stewart25-Jan-06 16:59 
GeneralRe: Can't make array class data shown in a label Pin
Albert8325-Jan-06 17:19
Albert8325-Jan-06 17:19 
Questioncopy Pin
quarinteen23-Jan-06 14:49
quarinteen23-Jan-06 14:49 
AnswerRe: copy Pin
Dave Kreskowiak23-Jan-06 15:32
mveDave Kreskowiak23-Jan-06 15:32 
QuestionPlease Solve with me this network Problem Pin
snouto23-Jan-06 12:50
snouto23-Jan-06 12:50 
AnswerRe: Please Solve with me this network Problem Pin
Dave Kreskowiak23-Jan-06 15:28
mveDave Kreskowiak23-Jan-06 15:28 
AnswerRe: Please Solve with me this network Problem Pin
Garry Stewart23-Jan-06 20:35
Garry Stewart23-Jan-06 20:35 
Questioninvoke codefile from a path embedded in XML? Pin
mattica23-Jan-06 12:19
mattica23-Jan-06 12:19 
AnswerRe: invoke codefile from a path embedded in XML? Pin
snouto23-Jan-06 12:56
snouto23-Jan-06 12:56 
GeneralRe: invoke codefile from a path embedded in XML? Pin
mattica23-Jan-06 18:15
mattica23-Jan-06 18:15 
GeneralRe: invoke codefile from a path embedded in XML? Pin
lmoelleb23-Jan-06 21:32
lmoelleb23-Jan-06 21:32 
Questionkeyboard sequence Pin
quasi478523-Jan-06 11:54
quasi478523-Jan-06 11:54 
QuestionTurn of word wrapping on labels Pin
dbrenth23-Jan-06 10:52
dbrenth23-Jan-06 10:52 

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.