Teaching Myself C Sharp Lesson 2 Understanding C# Programs

Every now and then we have bad or off days. One must have bad days now and then in order to be grateful for just the normal days. A bad day or moment helps us appreciate the normal times, sure they suck but tomorrows always another day. The reason I start with that is because after doing some work like I used to do in my old life, I realized that I was over it. I was over the physical exertion, the aggravation of my old injuries and the sun, oh the unmerciful sun. It motivated me and spurred me into action. If I want change, I must be the change, and no change comes without effort and persistence. So whilst today somewhat sucked, I will use it as motivation.
This is now lesson 2 and all my notes and research has been done through:
Sams Teach Yourself C# in 21 Days
2002 by Bradley L. Jones
win_20170123_19_18_41_pro
Chapter Two-Understanding C# Programs
day2understanding-programs
Object-Orientated Concepts
A object-orientated program is a language that uses objects. (Oh really?) There are three concepts that generally are associated with an object-orientated language.

Encapsulation: Is the concept of making packages that contain everything you need. It is putting everything that is needed into one group together in order to make an object or routine.

Polymorphism: Is the capability of assuming many forms as well as the ability to work withmystique_by_alexiscabo1-da2wk45.png multiple forms. (Awesome – Mystique like powers)

This can be applied to programming in a multiple of ways but are usually applied to two areas. You can call a routine in many different ways and still get the same result. An area of a circle object can be calculated using either 3 points or by using a single point and radius. Both will give you the same results but will depend upon the information entered/stored. Two programs will be written to get the information and can be given the same names. The program will then call on the circle routine and decide automatically which of the two routines should be used. Depending upon the information entered and stored, the relevant routine will be called.

Inheritance: Is the capability of inheriting all the characteristics of an object. Eg a circle can be turned into a sphere as it is a special kind of circle. By using the circle to create the sphere, the sphere can inherit all the properties of the circle plus add a bit more to create the sphere.

There is a fourth concept that is expected as a result of using c#.

Reuse: When you create a class you can reuse it to create lots of objects. By using inheritance and the other concepts you can create routines that can be used again in a number of different ways and in different programs. By encapsulating functionality you can create routines that have been tested and function correctly, this helps cut down on time and makes reusing these routines quick and easy.

Objects and Classes
A class is a definition for an item that will be created and the actual item created is an object. Classes are definitions used to create objects.
Class is like a cookie cutter.
It defines the object shape but is not the object.
You use the class to construct the same shaped objects over and over again.

Displaying Basic Information
There are two routines we use predominately to display text on screen:
System.Console.Writeline(): Prints the text on separate lines depending upon how many write-line routines there are.
System.Console.Write(): Prints the text on one line only and each write-line text will follow the last write-line routine on the same line.

day2displayinginformation
Conclusion Lesson 2

I learnt the difference between component-based and object-orientated.
Component-based development can be considered an extension of object-orientated programming. A component is a separate, stand alone section or piece of code that performs a specific task. A lot of these created components can be reused and then linked to build applications.
Composition is when one class (object) has another object within it.
Inheritance is when one class (object) is an expansion of another.

Quiz
1. What are the 3 types of comments?
Single line, multi line and document comments.
2. How are the 3 types of comments entered?
Single line: //
Multiple lines: */ ended with */
Documents: ///
3. What is the use of white-space for?
To make the code/program easier to read and follow. White-space is almost always                 ignored except in quoted text.
4. What is a literal?
A hard-coded value that cannot be changed.
5. What are the key concepts of object-orientated programming?
Encapsulation, polymorphism, inheritance and reuse.
6. Whats the difference between WriteLine() and Write()?
WriteLine() prints on a new line.
Write() prints on the same line.
7. What do you use as a placeholder when printing a value with WriteLine() or Write()?
Use a number between the braces {}. The first number value place is 0 and the next is 1.

That’s it for this lesson. Till next time:
Peace and blessings to you all.

Advertisements

One comment

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s