Click here to Skip to main content
15,891,607 members
Home / Discussions / C#
   

C#

 
AnswerRe: Windows 7: Getting The 'preview' file icon Pin
Ravi Bhavnani13-Oct-11 16:17
professionalRavi Bhavnani13-Oct-11 16:17 
GeneralRe: Windows 7: Getting The 'preview' file icon Pin
Michael Handschuh13-Oct-11 21:12
Michael Handschuh13-Oct-11 21:12 
GeneralRe: Windows 7: Getting The 'preview' file icon Pin
Ravi Bhavnani14-Oct-11 1:40
professionalRavi Bhavnani14-Oct-11 1:40 
QuestionVery basic OOP question Pin
SFORavi13-Oct-11 12:40
SFORavi13-Oct-11 12:40 
AnswerRe: Very basic OOP question Pin
PIEBALDconsult13-Oct-11 12:43
mvePIEBALDconsult13-Oct-11 12:43 
AnswerRe: Very basic OOP question Pin
Michael Handschuh13-Oct-11 13:14
Michael Handschuh13-Oct-11 13:14 
GeneralRe: Very basic OOP question Pin
SFORavi13-Oct-11 13:36
SFORavi13-Oct-11 13:36 
GeneralRe: Very basic OOP question Pin
Michael Handschuh13-Oct-11 13:51
Michael Handschuh13-Oct-11 13:51 
Well the problem is that all your variables in the employee class don't have public, or private set. In that case they will be private and only be seen within the class Employee.

To manage that the correct way, C# offers you the posibility to create so called "Properties".

I've created properties as you see in the code of the class.
C#
public class Employee
{

// This is another example of writing properties
/*
        private int eId;
        private string eName;
        private double age;

        public int EId
        {
           get{return eId;}
           set{eId = value;}
        }

        public string EName
        {
           get{return eName;}
           set{eName= value;}
        }

        public int Age
        {
           get{return age;}
           set{age= value;}
        }
*/
        // Properties
        public int EId{get;set;}
        public string EName{get;set;}
        public double Age{get;set;
 
        public Employee(int i, string n, double a)
        {
            eId = i;
            eName = n;
            age = a;
        }
 
        public Employee()
        {
 
        }
}


In the Form1 class you can access the properties pretty simple by creating a new Employee with Employee em = new Employee();
and access each property like: em.Name

C#
public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }
 
        private void button1_Click(object sender, EventArgs e)
        {
 

            int i1 = Convert.ToInt32(textBox1.Text);
            string nm = textBox2.Text;
            double d2 = Convert.ToDouble(textBox3.Text);
 
            Employee em = new Employee(i1, nm, d2);
 
 
          // Iam stuck on how to get the individual fields and display in separate box below.

            textBox5.Text = em.EId.ToString();
            textBox6.Text = em.EName;
            textBox6.Text = em.Age.ToString();
        }


Hope this helps.
GeneralRe: Very basic OOP question Pin
SFORavi13-Oct-11 14:02
SFORavi13-Oct-11 14:02 
GeneralRe: Very basic OOP question Pin
Not Active13-Oct-11 15:28
mentorNot Active13-Oct-11 15:28 
GeneralRe: Very basic OOP question Pin
SFORavi14-Oct-11 8:00
SFORavi14-Oct-11 8:00 
GeneralRe: Very basic OOP question Pin
BobJanova13-Oct-11 22:19
BobJanova13-Oct-11 22:19 
AnswerRe: Very basic OOP question Pin
arya168514-Oct-11 7:19
arya168514-Oct-11 7:19 
Questionajax refersh Pin
rupali srivastava13-Oct-11 10:22
rupali srivastava13-Oct-11 10:22 
AnswerRe: ajax refersh Pin
JP_Rocks20-Oct-11 3:27
JP_Rocks20-Oct-11 3:27 
QuestionUdpClient access denied exception Pin
David Knechtges13-Oct-11 8:48
David Knechtges13-Oct-11 8:48 
AnswerRe: UdpClient access denied exception Pin
Richard Andrew x6413-Oct-11 11:15
professionalRichard Andrew x6413-Oct-11 11:15 
AnswerRe: UdpClient access denied exception Pin
BobJanova13-Oct-11 22:15
BobJanova13-Oct-11 22:15 
QuestionC# ASP.NET Architecture .. Which one should we use ? Pin
UBX13-Oct-11 4:44
UBX13-Oct-11 4:44 
AnswerRe: C# ASP.NET Architecture .. Which one should we use ? Pin
BobJanova13-Oct-11 5:28
BobJanova13-Oct-11 5:28 
GeneralRe: C# ASP.NET Architecture .. Which one should we use ? Pin
UBX13-Oct-11 6:30
UBX13-Oct-11 6:30 
AnswerRe: C# ASP.NET Architecture .. Which one should we use ? Pin
Eddy Vluggen13-Oct-11 8:10
professionalEddy Vluggen13-Oct-11 8:10 
QuestionXPath expression Pin
NarVish13-Oct-11 2:31
NarVish13-Oct-11 2:31 
AnswerRe: XPath expression Pin
PIEBALDconsult13-Oct-11 3:18
mvePIEBALDconsult13-Oct-11 3:18 
GeneralRe: XPath expression Pin
NarVish13-Oct-11 3:26
NarVish13-Oct-11 3:26 

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.