Newb question. I am just begining to use C#
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums
Results 1 to 2 of 2

Thread: Newb question. I am just begining to use C#

  1. #1
    Join Date
    Feb 2012

    Newb question. I am just begining to use C#

    Hello guys,

    I am just starting to use C# for school. I like the program so far but I have lots to learn. I am having problems with properties. This is an assignment for school but I don't know how to do it.

    I need to know how to code the properties.
    This is the code so far:
    namespace Assignment2
    public class Student
    public Student(string n)
    Name = n;
    Record = new Transcript();
    // To do: Property implementation
    public string Name;
    public Transcript Record;
    public double GPA
    return Record.GPA;
    public int WealthPoints = 10000;
    public int PridePoints = 100;

    then I'm given a table to add some properties?
    this is what the table looks like:
    -m_record : Transcript
    -m_name : string
    -m_wealth : int = 1000
    -m_pride : int = 100
    + Student(string);
    +Name : string
    +WealthPoints : int
    +PridePoints : int
    +GPA : double
    +Record: Transcript

    Any advice would be really helpful. Thanks.

    I am using Visual C# 2010 Express

  2. #2
    Join Date
    Feb 2011
    United States

    Re: Newb question. I am just begining to use C#

    Sometimes it makes sense to encapsulate data by making the main state of an object hidden, but accessible through properties. For example, suppose I wanted to represent a person with a name (string) and age (int). I might write:

    public class Person
        //Declare private variables; accessible only within this class
        private string name;
        private int age;
        public Person(string newName, int newAge)
   = newName;
            this.age = newAge;
        //Other classes can both get and set a Person's name
        public string Name
            //Defines a getter method; always named get
            get { return; }
            /*Define a setter method; always named set
             *The setter method will accept an argument (in this case a string)
             * that will be stored in a reserved variable (keyword) called value
            set { = value; }
        //But let's only let them get (NOT modify) age
        public int Age
            //Define the getter
            get { return; }
            //But omit the setter
    Make sense?
    Last edited by BioPhysEngr; February 15th, 2012 at 08:59 PM. Reason: wrong bbcode
    Best Regards,

    All advice is offered in good faith only. You are ultimately responsible for effects of your programs and the integrity of the machines they run on.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Windows Mobile Development Center

Click Here to Expand Forum to Full Width

On-Demand Webinars (sponsored)