Basic of C#
A computer program is a set of instructions that you write
totell a computer what to do
¡ Programmers do not use machine language when creating computer programs. Instead, programmers tend to usehigh-level programming languages.
¡ Each high-level language has its
own syntax and limited set of vocabulary that is
translated into machine code by a compiler.
¡ In addition to understanding syntax, a programmer must also understand programming logic.
¡The goal of C# is to provide a simple, safe modern, object-oriented, Internet-centric, high-performance language for .NET development.
¡In .NET, programs are not compiled into executable files; they are compiled into Microsoft Intermediate Language (MSIL) files, which the CLR then executes. The MSIL (often shortened to IL) files that C# produces are identical to the IL files that other .NET languages produce; the platform is language- agnostic. A key fact about the CLR is that it is common; the same runtime supports development in C# as well as in VB.NET.
¡C# code is compiled into IL when you build your project. The IL is saved in a file on disk. When you run your program, the IL is compiled again, using the Just In Time (JIT) compiler .The result is machine code, executed by the machine's processor.
¡The CLS means that all .NET languages produce very similar IL code. As a result, objects created in one language can be accessed and derived from another. Thus it is possible to create a base class in VB.NET and derive from it in C#.
¡C# code is compiled into IL when you build your project. The IL is saved in a file on disk. When you run your program, the IL is compiled again, using the Just In Time (JIT) compiler .The result is machine code, executed by the machine's processor.
¡The CLS means that all .NET languages produce very similar IL code. As a result, objects created in one language can be accessed and derived from another. Thus it is possible to create a base class in VB.NET and derive from it in C#.
¡The essence of object-oriented programming is the creation of new types. A type represents a thing. Sometimes the thing is abstract, such as a data table or a thread; sometimes it is more tangible, such as a button in a window.
¡A type defines the thing's general properties and behaviors.
¡As in many object-oriented programming languages, in C# a type
is defined by a
class, while the individual instances of that class are known as objects.
¡ At the heart of any object-oriented language is its support for defining and working with classes.
¡ C# contains keywords for declaring new classes and their methods and properties, and for implementing encapsulation, inheritance, and polymorphism, the three pillars of object-oriented programming.
¡ C# contains keywords for declaring new classes and their methods and properties, and for implementing encapsulation, inheritance, and polymorphism, the three pillars of object-oriented programming.
- The essence of object-oriented programming is the creation of new types. A type represents a thing. Sometimes the thing is abstract, such as a data table or a thread; sometimes it is more tangible, such as a button in a window.
- A type defines the thing's general properties and behaviors.
- As in many object-oriented programming languages, in C# a type is defined by a class, while the individual instances of that class are known as objects.
- At the heart of any object-oriented language is its support for defining and working with classes.
- C# contains keywords for declaring new classes and their methods and properties, and for
implementing encapsulation, inheritance, and polymorphism, the three pillars of object-oriented
programming.
- A class is a blueprint that describes an object and defines attributes and operations for the object
Classes use abstraction to make available only the elements essential to defining the object - Classes use encapsulation to enforce an abstraction.
An object is an instance of a class.
Objects have the following qualities:
- Identity: Objects are distinguishable from
- Behavior: Objects can perform tasks
- State: Objects store information that can vary over time.
Fields
-The state of an object or type
Method
-Constructors
-Functions
-Properties (smart fields)
-Properties (smart fields)
Members come in two basic forms
Instance – per object data and methods
•Default
•Default
Static – per type data and methods
•Use the static keyword
•Use the static keyword
class HelloWorld
{
static void Main( )
{
// Use the system console object
System.Console.WriteLine("Hello World");
}
}
{
static void Main( )
{
// Use the system console object
System.Console.WriteLine("Hello World");
}
}
- A class has both properties and behaviors.
- Behaviors are defined with member methods;
- Member methods are sometimes called member functions that defines what a class can do or how it behaves.
- The CLR calls Main( ) when a program starts.
- Main( )is the entry point for your program
- Every C# program must have a Main( ) method.
Inheritance specifies an “is-a-kind-of” relationship. Multiple classes share the same attributes and operations, allowing efficient code reuse
Examples:
- A customer “is a kind of” person
- An employee “is a kind of” person
¡ A derived class inherits from a base class.
¡ Properties, methods, data members, events, and event handlers can be inherited (dependent on scope) .
¡ Keywords
§Inherits – inherits from a base class .
§NotInheritable – cannot be inherited from .
§MustInherit – instances of the class cannot be created; must be inherited from as a base class.
¡ Properties, methods, data members, events, and event handlers can be inherited (dependent on scope) .
¡ Keywords
§Inherits – inherits from a base class .
§NotInheritable – cannot be inherited from .
§MustInherit – instances of the class cannot be created; must be inherited from as a base class.



No comments:
Post a Comment