Click here to Skip to main content
15,890,579 members
Home / Discussions / C#
   

C#

 
GeneralRe: redirecting page in asp.net Pin
inaureen23-Jan-06 22:01
inaureen23-Jan-06 22:01 
QuestionTo Constantly ping the system. Pin
Venkat_8323-Jan-06 18:36
Venkat_8323-Jan-06 18:36 
AnswerRe: To Constantly ping the system. Pin
AB777124-Jan-06 0:34
AB777124-Jan-06 0:34 
AnswerRe: To Constantly ping the system. Pin
mitooki24-Jan-06 1:30
mitooki24-Jan-06 1:30 
QuestionConvert a 2003 project to a 2005 project Pin
NewbieDude23-Jan-06 18:16
NewbieDude23-Jan-06 18:16 
AnswerRe: Convert a 2003 project to a 2005 project Pin
M@dHatter23-Jan-06 18:33
M@dHatter23-Jan-06 18:33 
GeneralRe: Convert a 2003 project to a 2005 project Pin
NewbieDude23-Jan-06 18:39
NewbieDude23-Jan-06 18:39 
QuestionCan't make array class data shown in a label Pin
Albert8323-Jan-06 17:57
Albert8323-Jan-06 17:57 
Hi, I have created a program first as a console application. Then I created a windows application and copied the class data there. It is shown below. In the console application, I have used the printData() method to output the data of an instance of a Person or Athlete class. I want to do the same, but now that output should be in the label. I have created the printWindows data() function but when I call it from the main function in the for loop it doesn't work.

Any help would be appreciated.


namespace windowsPracticingWithClasses
{
///
/// Summary description for Form1.
///
public class Person : System.Windows.Forms.Form
{
///
/// Required designer variable.
///
private System.ComponentModel.Container components = null;

//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;

# region Properties
//Properties
public string FirstName
{
get { return firstName; }
set { firstName = value; }
}
and other properties.....

#endregion
//Custom constructor
public Person(int age, double height, double weight, string bankName, double bankAccount, double balance)
{
InitializeComponent();
this.age = age;
this.height = height;
this.weight = weight;
this.bankName = bankName;
this.bankAccount = bankAccount;
this.balance = balance;
}
public virtual void printData()
{
Console.WriteLine("\nProfile: \n\nAge: " + this.age);
Console.WriteLine("Height: " + this.height);
Console.WriteLine("Weight: " + this.weight);
Console.WriteLine("Bank Name: " + this.bankName);
Console.WriteLine("Bank Account: " + this.bankAccount);
Console.WriteLine("Balance: " + this.balance);
}
public void printWindowsData()
{
label1.Text += "Age: " + this.age;
label1.Text += "\nHeight: " + this.height;
label1.Text += "\nWeight: " + this.weight;
label1.Text += "\nBank Name: " + this.bankName;
label1.Text += "\nBank Account: " + this.bankAccount;
label1.Text += "\nBalance: " + this.balance;
}
class Athlete : Person
{
public string sport;
public Athlete(string sport) : base(23,5.6,120,"Chase",5671234,1000)
{
this.sport = sport;
}
public override void printData()
{
base.printData();
Console.WriteLine("Sport Practicing: " + this.sport);
}
};
class TestClasses
{
[STAThread]
static void Main()
{
Application.Run(new Person());
Person[] person = new Person[5];

person[0] = new Person(22,5.6,120,"Chase",5671234,2000);
person[0].printData();

Person[] athlete = new Athlete[3];

athlete[0] = new Athlete("Martial Arts");
athlete[0].FirstName = "Kim";
athlete[0].LastName = "Chung";
athlete[0].Age = 21;
athlete[0].Height1 = 5.7;
athlete[0].Weight = 130;
athlete[0].BankName = "Citi";
athlete[0].BankAccount = 212312;
athlete[0].Balance = 300;

for (int i = 0; i < athlete.Length; i++)
{
athlete[i].printWindowsData();
}
AnswerRe: Can't make array class data shown in a label Pin
AB777123-Jan-06 19:36
AB777123-Jan-06 19:36 
GeneralRe: Can't make array class data shown in a label Pin
Albert8324-Jan-06 9:40
Albert8324-Jan-06 9:40 
GeneralRe: Can't make array class data shown in a label Pin
AB777124-Jan-06 16:58
AB777124-Jan-06 16:58 
GeneralRe: Can't make array class data shown in a label Pin
Albert8324-Jan-06 20:04
Albert8324-Jan-06 20:04 
GeneralRe: Can't make array class data shown in a label Pin
AB777124-Jan-06 20:54
AB777124-Jan-06 20:54 
GeneralRe: Can't make array class data shown in a label Pin
Guffa23-Jan-06 20:41
Guffa23-Jan-06 20:41 
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 
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 

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.