C# Tutorial 6 Constructors Properties

33
20



Get the Code Here :
Best C# Book :
Support me on Patreon :

If you can’t donate a Like is Greatly Appreciated 🙂

In this part of my C# tutorial we cover public, private, protected, constants, read-only fields, constructors, setters, getters, properties and more on static. I’m taking my time to make sure everyone completely understands object oriented programming in C#. We are getting near the end of the basic syntax and will start doing fun stuff soon.

For best results take notes on the cheat sheet provided above as you watch and leave any questions you have.

Thank you to Patreon supporters like the following for helping me make this video

facebook.com/cottageindustriesbuild/
jaryd remillard : instagram: @distant_admiration
bugreplay.com
@kyleaisho
@thetwistedhat
vjFaLk
jaryd remillard :

Nguồn:https://wijstaanvooronzegrondrechten.org/

33 COMMENTS

  1. Hi Derek! 😀 Would you please explain if there will be other uses for properties? Or is it only exclusive for getting and setting fields?

    Thanks! Btw I love your tutorials, they're helping me out a lot.

  2. hı dear Derek Im gettıng 3 errors by this part and it says all the time that """Method must have a return type"""
    ı really didnt get this part could you help me please?and thanks for all this great works.

    public Animal()

    :this("No name", "No sound")

    { }

    public Animal(string name, string sound)

    :this (name,"No sound"){ }

  3. public string Name {get; set:} makes my head hurt! Inside the class what variable is Name? Inside the class how do I assign a string to Name? Do I use Name.value?

  4. You always nail it Derek. Perfect tempo, the right content and the right explanation for each concept. Thank you again yet one more time.

  5. At 13:42 in the constructor, NumofAnimals is set to 1, but later 17:50 when the fox was created, how did this number increment? There's no increment operation anywhere

    Edit: Allright, so everytime the constructor is run the 1 is the value that is used to increment numOfAnimals in 11:44 line 74

  6. Good video, but a bit confusing.
    I wish you could have differentiated the variable names by more than just a capitalized letter.

  7. Probably the best C# tutorial, you got such a great voice bro @Derek Banas, with a black background and high syntaxe ! thank you so much.

  8. 1 Question:
    Code:

    public Animal()
    :this("No name", "No sound") { }
    public Animal(string name)
    :this(name, "No sound") { }
    public Animal(string name, string sound) {
    this.name = name;
    this.sound= sound;
    }

    Is it the same as writing this:

    public Animal() {
    name = "No name";
    sound = "No sound";
    }
    public Animal(string name) {
    this.name = name;
    sound = "No sound";
    }
    public Animal(string name, string sound) {
    this.name = name;
    this.sound= sound;
    }

  9. The below throws a token error in VS 2013:
    public string Owner { get; set; } = "No Owner";

    I was able to get by this by declaring a private string called owner and setting Qwner to use it:

    public string Owner

    {

    get { return owner; }

    set { owner = value; }

    }

  10. So objects are the building units of the class? like(functions, variables, constructors) I'm confused between classes and objects

  11. Is there a difference between this:

    public int myInt{get; private set;}

    and this:

    private int _myInt;
    public int MyInt{get{return _myInt;}}

    ??

  12. Thanks for the GREAT videos – I love you rattle through at speed but with enough detail. Tried other courses, but you approach seems to work better for me. 🙂

    One to watch out for in case it confuses anyone watching – at about 9:50, there's a missing } else { when handling the length of sound. If it's too long, it gets set to "no name" then set it to the value even though too long.

  13. It looks as if your "sound = value" in the setter for sound is always going to apply, wiping out the previous error message. If so, you need an else clause.

LEAVE A REPLY

Please enter your comment!
Please enter your name here