C# Fundamentals for Absolute Beginners: (17) Working with Classes and Inheritances in the .NET Framework Class Library

Play C# Fundamentals for Absolute Beginners: (17) Working with Classes and Inheritances in the .NET Framework Class Library
Sign in to queue

Description

Embed

Download

Right click to download this episode

The Discussion

  • User profile image
    kushalxp

    Frankly Speaking ,
    i didn't understand the last three videos. 
    i watched it twice , thrice but sorry to say i didn't understand anything.
    can u please make me understand these thing more clearly..

  • User profile image
    BobTabor

    @kushalxp: Hi, sorry it's not helping ... can you articulate exactly what it is that is not making sense?  Are you having a hard time understanding WHY classes / etc. exist?  Or ...?

  • User profile image
    AbramTA

    I started to learn C# a week ago and I'm really thankful you for your series of lessons. They really help me in my first steps in this language, especially when I start my lessons about classes. It's so cool! Thank you for your series and for your fantastic teaching skills! 

  • User profile image
    KnipBE

    It didn't made sense to me too the first time I watched this (and the previous) video. What helped me a lot was printing out the code I wrote during this lesson and started writing next to every line what it did and where it got his values or to what it referred.
    Maybe this will help to those who doesn't understand this.

    Thanks @BobTabor for the great lessons!

  • User profile image
    CrazyRandomz​Z

    so for all who are having difficulty following along with these videos, here is my advice for you.

             don't just follow along, that's my key. anyone can just copy the code and see it working but the key is to modify, change, (fiddle) make it do what you want it to do, it may not be as optimized but if you can get it to display what you want then your on the right track. you will learn later on ways to improve and optimize the same code, but for now just get something solid working.

             //Comments are really important. the comment is a reminder of what is in the code, if you can write a good explanation after or before your code, it helps you remember and as you write the comment your also writing it into your memory, if you forget you can go back to that code and remember, but most the time you will remember. its also good practice to comment anything you do.

           don't stress, if you don't completely understand why something is doing what its doing but the outcome works then your doing OK. as you practice and follow the videos you will soon come to understand, if not google some examples and try decode  and understand it :) 

           Practice Practice Practice. using the info above, after each video try reproduce what was covered in that video, look back if you get stuck but try doing it by yourself.

    with that, you should find things a bit easier to follow, thanks @BobTabor for all your help so far i'm happy with what i can do and cant wait to start writing full programs. 

     

  • User profile image
    jli89

    Thank you for these easy to understand C# Tutorials Bob Tabor! 

    I'm still a little shaky on how the class instance works in thIs part of the code:

    Car myCar = new Car()

    // I understand that this makes it so you're able to work with the car class as an object in the method, but why does Car need to be typed before myCar?

     edit: I just realized that is where you define the variable type! Sorry about that!

    I was expecting to see string or int in that field from all the example that seeing Car there confused me.

  • User profile image
    classicoke

    what helped me was pausing the video every time an something important was stated (every 30 seconds or so). rewind and listen again if i didnt get it then:

    1. write down that statement in google drive document (example: method constructors, write down what they are and why you use them)
    2. heavy commenting in visual studio. sometimes i have 10 lines of comment for every line of actual code.
    3. make some adjustments to the code to challenge yourself.(example: subtract 1000$ of value from a car using what i learned from the DateTime video)

    i will probably never read most of what i write but writing down is, for me, a great way of learning faster.

  • User profile image
    Walter Craanen

    Great and simple to understand Instructions!
    I (still) write VB6 applications but I will (must?) go to C#.
    What I really want to know... Dear Bob, do you also have instructions videos to make C#-WindowFormsApplication connecting to a SQLserver database, retrieve record(sets) ect ect.. I hope so :)

  • User profile image
    arifuddin

    Dear Bob,

    i like it that you always try the most in simple language to make us understand. but actually this vdo has got lots of tough thing to understand.

    if u use more example then it might be easy. or any suggestion for book that might help us more. if you dont mind could you please tell me how is this book C# - HOW TO PROGRAM by DEITEL. so many tough words or terminology. completely lost.

  • User profile image
    BobTabor

    @arifuddin: I've not read that book, so I can't comment.  The focus of this lesson is to explain how Microsoft uses classes ... how one class inherits from another class.   They build a class that has basic functionality, then create other classes with more specialized / advanced functionality based on the original.  If you can understand that basic idea, you've gotten enough out of this lesson.  Don't worry about creating inheritance hierarchies in your applications ... that would require a bit more time and explanation as to why and how you do that.

  • User profile image
    Chowdary486

    @BobTabor

     

    HI

    i wrote the same code

    and i called the My truck with printcardetails

    but its printing only car details can u help me ?

     

    i am copying the code here

     

     

     

     

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;

    namespace Understanding_Inheritance
    {
        class Program
        {
            static void Main(string[] args)
            {

                Car Mycar = new Car();

                Mycar.make= "BMW";
                Mycar.model = "C CLASS";
                Mycar.year = 1990;
                Mycar.color = "black";

                printCarDetails(Mycar);

                TRUCK Mytruck = new TRUCK();

                Mytruck.year = 2000;
                Mytruck.make = "ford";
                Mytruck.model = "fista";
                Mytruck.color = "yellow";
                Mytruck.TowingCapacity = 12000;

                printCarDetails(Mytruck);
                Console.ReadLine();

            }




            private static void printCarDetails(Car car)
            {
                Console.WriteLine("Hear are the Car Details {0}", car.formatMe());
                Console.ReadLine();
            }
        }


        class Car
        {

            public string make { get; set; }
            public int year { get; set; }
            public string color { get; set; }
            public string model { get; set; }

            public string formatMe()
            {
                return String.Format("{0} - {1} - {2} - {3} "
                        , this.make
                        , this.year
                        , this.color
                        , this.model);
            }
            }

        class TRUCK : Car
        {
            public int TowingCapacity { get; set; }
        }


    }

  • User profile image
    BobTabor

    @Chowdary486:  Your code DOES WORK!  You added a second Console.ReadLine() therefore you MUST HIT THE ENTER KEY A SECOND TIME to see the Mytruck print out.  :)

    You do have one error in your code ... BMW doesn't make a C class.  :P

  • User profile image
    Chowdary486

    Thanks @BobTabor(a)   i am impressed with your videos and i subscribed to Learnvisualstudio.net :@  for 1 year

  • User profile image
    hanz

    Bob...you sir, are awesome! You make learning C# fun. You have +1 fan from now on.

  • User profile image
    Francis Decena

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;

    namespace ConsoleApplication2
    {
    class Program
    {
    static void Main(string[] args)
    {
    Console.WriteLine("Please Choose What type of Vehicle are you uisng \n 1: Car \n 2: Truck \n 3: Bus \n 4: Exit");
    int input = Convert.ToInt32(Console.ReadLine().ToString());

    if (input == 1)
    {
    Car Your_Car = new Car();

    Console.WriteLine("What Brand is your Car");
    Your_Car.Brand_vehicle = Console.ReadLine();

    Console.WriteLine("What Model is your Car");
    Your_Car.Model_vehicle = Console.ReadLine();

    Console.WriteLine("What Year is your Car");
    Your_Car.Year_vehicle = Convert.ToInt32(Console.ReadLine().ToString());

    Console.WriteLine("What Color is your Car");
    Your_Car.Color_vehicle = Console.ReadLine();
    printVehicleDetails(Your_Car);

    }
    else if (input == 2)
    {
    Truck Your_Truck = new Truck();

    Console.WriteLine("What Brand is your Truck");
    Your_Truck.Brand_vehicle = Console.ReadLine();

    Console.WriteLine("What Model is your Truck");
    Your_Truck.Model_vehicle = Console.ReadLine();

    Console.WriteLine("What Year is your Truck");
    Your_Truck.Year_vehicle = Convert.ToInt32(Console.ReadLine().ToString());

    Console.WriteLine("What Color is your Truck");
    Your_Truck.Color_vehicle = Console.ReadLine();

    Console.WriteLine("What is the Towing Capacity of your truck");
    Your_Truck.TowingCapacity = Convert.ToDouble(Console.ReadLine().ToString());
    printVehicleDetails(Your_Truck);

    }
    else if(input == 3)
    {
    Bus Your_Bus = new Bus();

    Console.WriteLine("What Brand is your Truck");
    Your_Bus.Brand_vehicle = Console.ReadLine();

    Console.WriteLine("What Model is your Truck");
    Your_Bus.Model_vehicle = Console.ReadLine();

    Console.WriteLine("What Year is your Truck");
    Your_Bus.Year_vehicle = Convert.ToInt32(Console.ReadLine().ToString());

    Console.WriteLine("What Color is your Truck");
    Your_Bus.Color_vehicle = Console.ReadLine();

    Console.WriteLine("What is the Seating Capacity of your bus");
    Your_Bus.Seating_Capacity = Convert.ToDouble(Console.ReadLine().ToString());
    printVehicleDetails(Your_Bus);
    }
    else if (input == 4)
    {
    Environment.Exit(0);
    }
    else
    {
    Console.WriteLine("Invalid Enter");
    }

    Console.ReadLine();
    }
    public static void printVehicleDetails(Vehicle vehicle)
    {
    Console.WriteLine("Your Vehicle Information is {0}", vehicle.Formatme());
    Console.ReadLine();
    }
    public abstract class Vehicle
    {
    public string Brand_vehicle { get; set; }
    public string Model_vehicle { get; set; }
    public int Year_vehicle { get; set; }
    public string Color_vehicle { get; set; }

    public abstract string Formatme();
    }
    public class Truck : Vehicle
    {
    public double TowingCapacity { get; set; }

    public override string Formatme()
    {
    return String.Format("{0} - {1} - {2} - {3} - {4}",
    this.Brand_vehicle,
    this.Model_vehicle,
    this.Year_vehicle,
    this.Color_vehicle,
    this.TowingCapacity);

    }

    }
    public class Bus : Vehicle
    {
    public double Seating_Capacity { get; set; }

    public override string Formatme()
    {
    return String.Format("{0} - {1} - {2} - {3} - {4}",
    this.Brand_vehicle,
    this.Model_vehicle,
    this.Year_vehicle,
    this.Color_vehicle,
    this.Seating_Capacity);
    }

    }
    public class Car : Vehicle
    {

    public override string Formatme()
    {
    return String.Format("{0} - {1} - {2} - {3}",
    this.Brand_vehicle,
    this.Model_vehicle,
    this.Year_vehicle,
    this.Color_vehicle);

    }

    }

    }

    }

    Hi Bob Thanks for the video it helped me a lot. I just try your sample code and came up with my own version in it... thanks again and have a good day...

  • User profile image
    CSharp​Fanatic

    I like the way of introducing .Net framework library along with the conceptual theory. After several weeks of trying out with several sites as reference for learning C#, I got settled over here. This is wonderful and I am able to follow every line in the session.

  • User profile image
    chris

    Best C# tutorial available, thank you.

  • User profile image
    maureenmj1

    Hello Bob,

    I am a raw beginner.  So, it is a bit of a struggle street.

    Thanks for the videos.  My question is, in regard to  Video 17, "Working with Classes and Inheritances in the .NET Framework Class Library"

    Specifically

    Truck myTruck = new Truck

    When you print it to screen,  there is no clear definition between what is a car and what is a truck.  The printout is just telling you that one is a "Ford" and the other is a "BMW".  Both could be cars or both could be trucks since Ford and BMW both produce cars and trucks.  How can you make the "child class" show that it is indeed a truck?
    Kind regards

    maureenmj1

  • User profile image
    maureenmj1

    Hello Bob

    My question was premature.

    Question answered.

    I hope I didn't waste too much of your time.

    Kind regards

    maureenmj1

  • User profile image
    swaroopy660

    Hello Bob ,

    I was watching your tutorials since past week . I have some doubts regarding 15th tutorial 

    double marketValueOfcar = determineMarketValue (myNewcar) ;

    why did you pass a parameter in the parenthesis ??

    You could have simply created object but what is the use of passing parameter in the parenthesis (myNewcar) ???? 

    Why do we pass parameters ???

    Regards ,

    Swaroop .

  • User profile image
    Scott

    I don't normally comment on stuff on the internet but I just wanted to say that these tutorial videos are absolutely fantastic. The content has been really great to follow along with and I'm really grabbing hold of the concepts rather than just following along and repeating what is instructed.

    I just wanted to say thanks for creating these videos! Bob, you've a fantastic personality and everything has been incredibly helpful and fun to learn!

  • User profile image
    Charles M

    Hi Bob,

    First off, these videos have been an awesome resource for learning C#, Visual Studios, and all the other content. Thank you very much for making these.

    I've completed all of the videos up to this point and I'm working on 17 "Working with Classes and Inheritances in the .NET Framework Class Library"

    I've started writing what I saw on the tutorial, but when i fire up the debug I get the error:

    An unhandled exception of type 'System.FormatException' occurred in mscorlib.dll

    Additional information: Input string was not in a correct format.

    I double checked my code and I can't seem to find where I strayed away (besides not spelling Inheritance correctly when naming the project :P). Below is what I have completed:

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;

    namespace UnderstandingInheritant
    {
    class Program
    {
    static void Main(string[] args)
    {
    Car myCar = new Car();
    myCar.Make = "BMW";
    myCar.Model = "745li";
    myCar.Color = "Black";
    myCar.Year = 2005;

    printCarDetails(myCar);

    Console.ReadLine();
    }

    private static void printCarDetails(Car car)
    {
    Console.WriteLine("Here are the car's details: {0}",
    car.FormatMe());
    }

    }

    class Car
    {
    public string Make { get; set; }
    public string Model { get; set; }
    public int Year { get; set; }
    public string Color { get; set; }

    public string FormatMe()
    {
    return String.Format("{0} - {1} - {2) - {3}",
    this.Make,
    this.Model,
    this.Color,
    this.Year);
    }
    }

    }

    Any help is appreciated, and thank you again.

    Charles

  • User profile image
    Charles M

    I found it! I used a ) instead of } in the line:

    return String.Format("{0} - {1} - {2) - {3}",

    Almost lost my mind looking for it.

  • User profile image
    Aaron

    Thank you! Still awesome teaching 3 (or more?) years later! I've gleaned from your tutorials enlightenment on a few concepts that my previous studies in Java had not elucidated, even after a more lengthy stretch. There have certainly been some extension of the logic in those other studies that this tutorial does not demand, but your tutorials provide a great foundation from which I feel much more confident that I can endeavor to extend my current knowledge beyond its confines. I'm really excited to try to find the next level of tutorials once i complete these, LearnVisualStudio.net perhaps?

  • User profile image
    SnipeHub

    Very nice, just starting to get it now, was confused in the previous class examples, just getting it now, wow. Thanks

  • User profile image
    john

    Can you use the abstract/virtual keywords on "private methods" or does the methods have to be public? Is there any relationship between abstract/virtual/sealed and the private/public keywords? thanks

Add Your 2 Cents