ALERT!
Click here to register with a few steps and explore all our cool stuff we have to offer!

Jump to content



Photo

Learn C# Vol*2 Part 1 Introduction.


  • Please log in to reply
Learn C# Vol*2 Part 1 Introduction.

#1

PandaAzul
PandaAzul
    Offline
    2
    Rep
    17
    Likes

    Advanced Member

Posts: 126
Threads: 12
Joined: Jul 17, 2015
Credits: 0
Eight years registered
#1

                 Hi again people. Today they teach the classes in C #

                                                   Part   1°

 

 

Introduction to C# classes:

 

In lots of programming tutorials, information about classes will be saved for much later. However, since C# is all about Object Oriented programming and thereby classes, we will make a basic introduction to the most important stuff already now. 

First of all, a class is a group of related methods and variables. A class describes these things, and in most cases, you create an instance of this class, now referred to as an object. On this object, you use the defined methods and variables. Of course, you can create as many instances of your class as you want to. Classes, and Object Oriented programming in general, is a huge topic. We will cover some of it in this chapter as well as in later chapters, but not all of it. 

In the Hello world chapter, we saw a class used for the first time, since everything in C# is built upon classes. Let's expand our Hello world example with a class we built on our own.

 

Hidden Content
You'll be able to see the hidden content once you reply to this topic or upgrade your account.

 

Okay, lots of new stuff here, but almost all of it is based on stuff we've already used earlier in this tutorial. As you can see, we have defined a new class, called Car. It's declared in the same file as our main application, for an easier overview, however, usually new classes are defined in their own files. It defines a single variable, called color, which of course is used to tell the color of our car. We declared it as private, which is good practice - accessing variables from the outside should be done using a property. The Color property is defined in the end of the class, giving access to the color variable. 

 

Besides that, our Car class defines a constructor. It takes a parameter which allows us to initialize Car objects with a color. Since there is only one constructor, Car objects can only be instantiated with a color. The Describe() method allows us to get a nice message with the single piece of information that we record about our. It simply returns a string with the information we provide. 

Now, in our main application, we declare a variable of the type Car. After that, we create a new instance of it, with "Red" as parameter. According to the code of our class, this means that the color red will be assigned as the color of the car. To verify this, we call the Describe() method, and to show how easy we can create several instances of the same class, we do it again, but with another color. We have just created our first functional class and used it. 

In the following chapters, concepts like properties, constructors and visibility will be explained in more depth.

 


  • 1

#2

Tousensito
Tousensito
    Offline
    0
    Rep
    4
    Likes

    New Member

Posts: 18
Threads: 0
Joined: Aug 28, 2015
Credits: 0
Eight years registered
#2

ty


  • 1

#3

KhEmil
KhEmil
    Offline
    0
    Rep
    0
    Likes

    HowToLeecher

Posts: 12
Threads: 0
Joined: Aug 12, 2015
Credits: 0
Eight years registered
#3

nice idea men


why my leecher lvl get higher?!


i did nothing


  • 0

#4

bluestones
bluestones
    Offline
    2
    Rep
    1
    Likes

    Advanced Member

Posts: 142
Threads: 0
Joined: Jul 12, 2015
Credits: 0
Eight years registered
#4

TY!!! Love to follow the lecture #2  :)

bstones 


  • 0


 Users browsing this thread: