.NETGURU
Defining and using structures within class
Messages   Related Types
This message was discovered on ASPFriends.com 'aspngcs' list.


edp
-- Moved from [aspngdatagridrepeaterdatalist] to [aspngcs] by Victor Von Doom <Click here to reveal e-mail address> --

Hi All :

Is this the best method by which I can define and used structures within classes.

The way I do it this way is that I want to modularise my code by restricting access to this data structure to users of this class.

Is there another way to do it ??? Should I initialise the class beforehand or is it OK to do it like I have done below :

****************
class classroom {
public struct student {
string _firstname;
string _lastname;
int _age;
public string firstname {
get {return _firstname;}
}
public string lastname {
get {return _lastname;}
}
public int age {
get {return _age;}
}
public student(string f, string l, int a)
{
_firstname = f;
_lastname = l;
_age = a;
}
}
}

public void showstudents(Object sender, EventArgs e)
{
classroom.student[] array_of_students =
{new classroom.student("Tom", "Cruise", 36), new classroom.student("Bruce", "Willis", 40)};
Label1.Text = array_of_students[1].firstname;
Label2.Text = array_of_students[1].age.ToString();
}

****************

Reply to this message...
 
    
Tim Musschoot
I would use the 'class' specification instead of a struct (didn't even
know 'struct' still existed in C#). Initializing is done automatically
: all members are NULL. Are you sure the struct student is not
available outside the class? I would mark it protected...

-----Oorspronkelijk bericht-----
Van: edp [mailto:Click here to reveal e-mail address]
Verzonden: zaterdag 17 augustus 2002 5:47
Aan: aspngcs
Onderwerp: [aspngcs] Defining and using structures within class

-- Moved from [aspngdatagridrepeaterdatalist] to [aspngcs] by Victor Von
Doom <Click here to reveal e-mail address> --

Hi All :

Is this the best method by which I can define and used structures within
classes.

The way I do it this way is that I want to modularise my code by
restricting access to this data structure to users of this class.

Is there another way to do it ??? Should I initialise the class
beforehand or is it OK to do it like I have done below :

****************
class classroom {
public struct student {
string _firstname;
string _lastname;
int _age;
public string firstname {
get {return _firstname;}
}
public string lastname {
get {return _lastname;}
}
public int age {
get {return _age;}
}
public student(string f, string l, int a)
{
_firstname = f;
_lastname = l;
_age = a;
}
}
}

public void showstudents(Object sender, EventArgs e)
{
classroom.student[] array_of_students =
{new classroom.student("Tom", "Cruise", 36), new
classroom.student("Bruce", "Willis", 40)};
Label1.Text = array_of_students[1].firstname;
Label2.Text = array_of_students[1].age.ToString();
}

****************
| [aspngcs] member Click here to reveal e-mail address = YOUR ID
| http://www.asplists.com/asplists/aspngcs.asp = JOIN/QUIT

Reply to this message...
 
 
System.EventArgs




ExamGuru IT Solutions - .Net Guru is owned and operated by ExamGuru, Inc., the man behind .Net Guru. If you're in the market for bespoke software or software consultancy, why not get him and his highly trained team to help? - www.examguru.net/ITCertification
Ad


Need Dot Net Interview Questions?
Ask ExamGuru, Inc. for advice and help on Passing .Net Interviews
.Net Projects
Best-of-breed application framework for .NET projects, developed by ExamGuru, Inc. and ExamGuru IT
Free .net Help
Commission ExamGuru, Inc. and his team for your next bespoke software project
FogBUGZ
The only bug tracking system carefully crafted with one goal in mind: helping teams create great software.
Awesome Tools
If you don't know about these, you're missing out... IT Certification Questions
IT Interview Questions
Free Oracle 10g Training
MCSE Boortcamp
Cisco Study Guides
Cheap Study Guides
Exact Questions
Dot Net Interview Questions
Oracle OCP
Cheap Travel
Designer Perfumes - Wholesale Prices
Free Programming Tutorials
 
ExamGuru IT Solutions - .Net Guru is owned and operated by ExamGuru, Inc., the man behind .Net Guru. If you're in the market for bespoke software or software consultancy, why not get him and his highly trained team to help? - www.examguru.net/ITCertification
 Copyright © ExamGuru, Inc. 2001-2006
Contact Us - Terms of Use - Privacy Policy - www.dot-net-guru.com - www.examguru.net - www.oraclesource.net - www.itinterviews.net - www.examguru.net/ITCertification