C# Tutorial 6 Constructors Properties

[ad_1]
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 :


Posted

in

by

Tags:

Comments

29 responses to “C# Tutorial 6 Constructors Properties”

  1. T Riddle Avatar

    Derek. I'm using Visual Studio 2017 and I can't get it to accept line 76 of this tutorial
    if (!name.Any(char.IsDigit))

    I get Error CS106 'string' does not contain a definition for 'Any' and no extension method 'Any' accepting a first argument of type 'string' could be found (are you missing a using directive or an assembly reference?)

    Any ideas?

  2. Nicklas Isaksson Avatar

    This is what i do every day. Like Your videos.

  3. Maaz Shaikh Avatar

    Didn't understand why :this is used.
    Can someone pls teach me!!

  4. smtktc Avatar

    this guy is like Bob Ross of programming.

    we have happy little code sniplets over here

  5. Jakub Rapant Avatar

    I would like to ask about your logic inside setter for sound. The time is 9:33. U used if statement without else, so if length is more than 10, you set sound variable as "No Sound" but then rest of code is executed and sound will be set as value.

  6. brixtongun Avatar

    Do you have any videos where you explain the link between basic syntax's and how they work in programs?

  7. Andrew Ignatov Avatar

    Well, thanks for your course, it helped me a lot. Your work is amazing!
    I have one question, maybe it had been already asked. At the beginning you created method MakeSound, that allows us to avoid writing Console.WriteLine etc. Then why didn"t you use it?

  8. Kerreber Avatar

    Rawrrr hahaha, very nice tutorial again

  9. German Cedres Avatar

    Really love your tutorials, but the voice is too low, D:.

  10. Darin Hensley Avatar

    Is there a error in this video? I thought you stated that private can be accessed in derived classes but ms docs state only same class or struct.

  11. I Think, You Imagine Avatar

    Hi Derek!

    A few bugs I am encountering:
    At 5:00 you are explaining the constructors (with the ":this" part), however, my code keeps erroring in a way that isn't quite clear to me. I'm not sure if this is because of an error on my end, or an update to C# since your tutorial was made, but, I get:

    [Animal (default constructor)] : Method must have a return type
    [Animal (default constructor)] : Unexpected token ':'

    Is there something I am missing, or is this a C# change?

    //Code in case you need to see it\

    public Animal()
    :this("No Name", "No Sound") { }

    Another place I am encountering bugs is the 'idNum' part where you are defining the read-only value (even when I completely copy and paste the code from your website).

    [idNum] : A read-only field cannot be assigned to (except in a constructor or a variable initializer)

    Again, I'm not sure if these are C#-side errors, or if I am missing something.

    Thanks! 😀

    P.S. Rawrrr

  12. Eames Trinh Avatar

    1. Rawrrr
    2. 6:30 You can use methods as parameters? I know this is possible in JS, but how does it work in C#?

  13. li li Avatar

    Thanks for the tutorial, Derek! For the setter of numOfAnimals, you use numOfAnimals += value, while you use numOfAnimals = 1 in constructor. If we use numOfAnimals = value in the setter, and numOfAnimals += 1 in the constructor. Will that code work? Which one prefers to be used in the real world?

  14. Yazid Avatar

    things started to get a little bit confusing, but i'll keep following the serie 🙂 thanks a lot!

  15. David Kim Avatar

    Can anyone explain what the "this" keyword is used for? Thanks 🙂

  16. Alpine Mobile Avatar

    At the beginning of the the video, what do you mean when you say you want to make it hard for the user to go in and change the field data? What user are you talking about? Where would the user go in? the source code? Why would you say hard and not impossible? It could still be modified by the user, if he tried harder? Help me understand please.

  17. Sahludheen vn Avatar

    Thank you so much.
    Sir , i want learn a programming language . but confused, which one better for future?
    i don't have any adviser.help me
    Sir… please replay this Comment

  18. inototen Avatar

    the line public string Owner { get; set; } = "No Owner"; is not working for me
    it shows an CS1519 error, says that the "=" is a invalid token in class, struct or interface declaration

  19. Sahludheen vn Avatar

    Thank you so much.
    Sir , i want learn a programming language . but confused, which one better for future?
    i don't have any adviser.help me

  20. Trystan34 Avatar

    Hi Derek. I am not sure if you are using Visual Studio 2015 or not but VS 2015 and above you can use the C# 6 feature for formatting strings. Instead of using {0} in the string format you can directly reference the variable if you use a $ before the first quotes eg. Console.WriteLine($"{name} says {sound}"); instead of Console.WriteLine("{0} says {1}",name,sound);

  21. Jakub Gause Avatar

    Hello Derek,

    I decided to try learn C# and overall programming to the depth. So I decided to buy C# 6.0 and the .NET 4.6 Framework by Troelsen and Japiksen, because of many positive reviews, same as your opinion that it's best C# book.

    I already did some programing with Python, C, Java and even in C# (only on noob level), but I really can get into that book :D, I am sure it is excelent book, but I am in first chapter: The Philosophy of .NET and I really dont know what they are talking about :D. It's because of me, that I am too dumb for programming?
    I have feeling like they expecting that I already know something when I start with this book, they throwing on me things like assemblies, LINQ and other stuff. Yea I heard about that, but really dont know exactly what it does and in books they say for example what all things you can do with it and when it used, thats nice but, first of all I need to know well what exactly that that things does itself.
    I don't want to go to next chapter when this chapter I. have to lay the conceptual groundwork for the remainder of the book, as they said on start of that chapter.

    So I want to ask you that already read this book, it's good for me to start with this book? or is it already for better programmers?, but please remember I really would like to go to depth of programing so if I have just to swallow this for now and let it flow (that I don't understand everything now) and I will understand it later in book?

    BTW your videos really helping me with learning C#, Thank you.

  22. ramsy rama Avatar

    Number one fun here.love every bit of it

Leave a Reply

Your email address will not be published. Required fields are marked *