Learn and understand constructors in C# 🔥Get the COMPLETE Course: bit.ly/2LhL39u SUBSCRIBE FOR MORE VIDEOS! / @programmingwithmosh STAY IN TOUCH / programmingwithmosh / moshhamedani
Drabantor Greyhound Your comment is interesting as it is surprising how often these types of videos are unusable because they miss the mark on one of your criteria.
This was very smooth and easy to follow, thank you! For those not using ReSharper when making a new class do not add a namespace and if it has one remove it or your class will not work!
Thank you for your tutorials. They have been very helpful. If I may offer something in return, hold down "Ctrl + Shift + A". That is the keyboard shortcut for creating a "new something" for example the first item is often a new class. Just title it and hit enter. Saves time manually right clicking and searching. Thank you again for your help :)
Thank you. I did not know that when we create a constractor, the default one disappears and we need to declare parametrless constractor. You answered the question I had so many troubles with)) I wish I watched this earlier)) Thank you
I have a question. Why after you run it in 13:04 you get "press any key to continue"? For me the breakpoint makes it print only "1" and "John" is not displayed. I added Console.ReadLine() after and removed the breakpoint to get a similar effect, but I like your way much better. Please tell me how to get it this way. And anyway thanks a lot for this video!
Hey, thanks a lot, great videos in this channel, i subscribe, everything is clear. voice/presentation/Steps order, i learn more from u, thanks for all.
If you get an error when running the code, double check that you Console.WriteLine(costumer.ID) and not console.WriteLine(Costumer.ID) with a capital C. if you use capital C you try to output the class ID and not the object you created from the class.
Good tutorial. Resharper is great but right clicking add class isn't a big deal, don't turn it into one. Most people here aren't professionals we are just here to learn. It's good to learn how to do things manually especially as newbies.
So this is definitely more advanced topic than I am ready for. About half way through I'm literally just sitting there wondering what the heck he is even doing because I have no idea what constructors are and these other advanced topics. I'm going do some more reading and practicing and hopefully return to this topic later on when I know what a few of these things mean. However, that being said it's a good tutorial talking about Code Sharpner ect just not for beginners like myself at this time.
Hi can I ask something can you help me with the errors in visual studio with connect string : 'A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible. Verify that the instance name is correct and that SQL Server is configured to allow remote connections. (provider: Named Pipes Provider, error: 40 - Could not open a connection to SQL Server)' Thanks you
You probably know this by now, but for other people: Make sure that your IP address is whitelisted or the IP permissions constraint is disabled. Make sure that you spelled everything correctly and did not include the "..." in the server URL (include only: " some-server-name.database.windows.net "). Make sure that you specified the correct initial database name. Make sure that you provided all the minimum necessary parameters and the correct order when connecting via a connection string. Make sure that the database server and database are available for remote connections. Good luck!
Hi Mosh, thank you for the great video! I have a question: is it wrong to initialize variables or objects once you declare them instead of doing that in the constructor?? Thanks in advance!
He uses a default constructor to initialize the List, this in itself is bad practice and should be done inline within the field itself, so the field should look like this: List orders = new List(); NOT: List orders;
Great tutorial for constructors concept, thanks a lot! I just got a bit confused at the end when you describe about list of orders, it could be better to put an example there (rather than empty list maybe?).
the list is basicaly a box you can store things inside. "list" tells the program to make a box you can put things inside, "" describe what you are allowed to put inside this box. In this case only objects created by the class "orders" are allowed to be put inside this box. if he wrote list you could only put strings inside the box. It is abit confusing that he used a custom designed object as an example for what to put inside a list, i agree...
What is the difference between var order = new Order() & customer.Orders = new List(); Also, I can't put var order = new Order() in the Customer() class. VS always tells me that I need another instance. So I always instance twice, instead of once.
Hi Mosh. Thanks for explaining this topic well :). I just want to ask why "this." isn't needed for the "Orders" when you initialized it in the first Customer constructor? So "this.Orders = "
Maybe because it is in the default constructor you don't need thi? docs.microsoft.com/en-us/dotnet/csharp/programming-guide/classes-and-structs/instance-constructors
I'm new at coding and wanna make sure I learn the correct conventions, I have a question : Shouldn't we be using camelCase for fields ? I learned that PascalCase was supposed to be used for properties. ex : public class Human { //camelCase for the field : public int age; //PascalCase for the property: public int Age { get {return age;} set { if (value < 0) { age = 0; } else { age = value; } } } } Thank you in advance to whoever answers me.
Why not.. In the Costumer Class, as a property.. you don't type this = public List Orders = new Lisy() ; And it will be always initialized without using a Constructor. Why not?
In all his videos about C#, Mosh is basically telling us "If you don't have Resharper, I'm sorry for you" and I'm actually very sorry for me cause of that :< I had it once, now I don't and it's such a loss...