Jump to content


Check out our Community Blogs

Register and join over 40,000 other developers!


Recent Status Updates

View All Updates

Photo
- - - - -

C# : need help in classes and properties

c# classes properties

Best Answer WingedPanther73, 12 August 2014 - 09:19 AM

You've asked a very, VERY broad question, to start with.

 

The code you've posted is a class called Voiture, with a private property vitessePrivee that is an int (it cannot be accessed directly from outside the class), and an accessor called Vitesse that is designed to give controlled access to vitessePrivee.

 

In and of itself, the code does very little. If voit was an instance of Voiture, you would set and return the value in vitessePrivee using voit.Vitesse.

Go to the full post


This topic has been archived. This means that you cannot reply to this topic.
8 replies to this topic

#1 haythem

haythem

    CC Newcomer

  • Member
  • PipPip
  • 17 posts

Posted 12 August 2014 - 07:31 AM

hey 

can someone explain to me classes and there properties in c#?

also explain this code plz :)

public class Voiture
{
    private int vitessePrivee;
    public int Vitesse
    {
        get
        {
            return vitessePrivee;
        }
        set
        {
            vitessePrivee = value;
        }
    }
}


#2 WingedPanther73

WingedPanther73

    A spammer's worst nightmare

  • Moderator
  • 17757 posts

Posted 12 August 2014 - 09:19 AM   Best Answer

You've asked a very, VERY broad question, to start with.

 

The code you've posted is a class called Voiture, with a private property vitessePrivee that is an int (it cannot be accessed directly from outside the class), and an accessor called Vitesse that is designed to give controlled access to vitessePrivee.

 

In and of itself, the code does very little. If voit was an instance of Voiture, you would set and return the value in vitessePrivee using voit.Vitesse.


Programming is a branch of mathematics.
My CodeCall Blog | My Personal Blog

My MineCraft server site: http://banishedwings.enjin.com/


#3 haythem

haythem

    CC Newcomer

  • Member
  • PipPip
  • 17 posts

Posted 12 August 2014 - 01:43 PM

 an accessor called Vitesse that is designed to give controlled access to vitessePrivee.

 

In and of itself, the code does very little. If voit was an instance of Voiture, you would set and return the value in vitessePrivee using voit.Vitesse.

 

i didnt understand this :/



#4 WingedPanther73

WingedPanther73

    A spammer's worst nightmare

  • Moderator
  • 17757 posts

Posted 13 August 2014 - 05:20 AM

Do you know what an accessor is? It's a method that acts like a property to limit how you can read/write to properties.


Programming is a branch of mathematics.
My CodeCall Blog | My Personal Blog

My MineCraft server site: http://banishedwings.enjin.com/


#5 haythem

haythem

    CC Newcomer

  • Member
  • PipPip
  • 17 posts

Posted 13 August 2014 - 06:38 AM

ok i understand but what did you mean by : 

In and of itself, the code does very little. If voit was an instance of Voiture, you would set and return the value in vitessePrivee using voit.Vitesse.



#6 WingedPanther73

WingedPanther73

    A spammer's worst nightmare

  • Moderator
  • 17757 posts

Posted 13 August 2014 - 08:12 AM

Voiture voit = new Voiture;
voit.Vitesse = 12; //sets voit.vitessePrivee to 12
console.write(voit.Vitesse); //outputs 12 from the value in vitessePrivee

Realizing my C# is crazy rusty, that's the basic idea.


Programming is a branch of mathematics.
My CodeCall Blog | My Personal Blog

My MineCraft server site: http://banishedwings.enjin.com/


#7 haythem

haythem

    CC Newcomer

  • Member
  • PipPip
  • 17 posts

Posted 13 August 2014 - 09:52 AM

yes thank you i understand that code now .... but can you explain to me the : set ans get commands please?



#8 WingedPanther73

WingedPanther73

    A spammer's worst nightmare

  • Moderator
  • 17757 posts

Posted 13 August 2014 - 11:27 AM

In the code above, voit.Vitesse = 12 actually calls "set" with 12 as value. Similarly, console.write(voit.Vitesse) actually calls the "get".


Programming is a branch of mathematics.
My CodeCall Blog | My Personal Blog

My MineCraft server site: http://banishedwings.enjin.com/


#9 haythem

haythem

    CC Newcomer

  • Member
  • PipPip
  • 17 posts

Posted 13 August 2014 - 11:31 AM

ok thanks a lot this helped so much






Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download