introduction c sharp pdf and basic concepts of c# programming language
0 Introduction of C
0 History of C
0 Design Goals
0 Why C? : Features
0 C & Object-Oriented Approach
0 Advantages of C
0 Applications of C
0 Introduction to .Net Framework
0 History of .Net
0 Design Features
0 .Net Architecture
0 .Net & Object Oriented Approach
0 Application of .NET : GUI
0 Wrapping Up
0 References INTRODUCTION TO C
0 C is a multi-paradigm programming language which is based on object-
oriented and component-oriented programming disciplines.
0 It provides a framework for free intermixing constructs from different
0 It uses the “best tool for the job” since no one paradigm solves all problems in
the most efficient way. BRIEF HISTORY
0 C was developed by Microsoft with Anders Hejlsberg as the principal
designer and lead architect, within its .NET initiative and it made its
appearance in 2000.
0 Anders Hejlsberg and his team wanted to build a new programming language
that would help to write class libraries in a .NET framework. He claimed that
C was much closer to C++ in its design.
0 The name "C sharp" was inspired by musical notation where a sharp indicates
that the written note should be made a semitone higher in pitch.
0 Ever since its inception, C has controversially been stated as an imitation of
Java. However, through the course of time, both Java and C have exhibited
distinct features which support strong object-oriented design principles.
0 C was intended to be a simple, modern, object-oriented language.
0 The language and implementation had to provide support for software
engineering principles like strong type checking, array bounds checking and
automatic garbage collection.
0 The language was intended for development of software components
suitable for deployment in distributed environments.
0 Source code portability was important for programmers who were familiar
with C and C++.
0 Support for internalization to adapt the software to different languages. WHY C ? : FEATURES
0 C is the first “component-oriented” language in the C/C++ family.
0 The big idea of C is that everything is an object.
0 C is a programming language that directly reflects the underlying Common Language
Infrastructure (CLI). Most of its intrinsic types correspond to value-types implemented by
the CLI framework.
0 Type-safety: C is more type safe than C++. Type safety is the extent to which
a programming language discourages or prevents type errors.
0 C, like C++, but unlike Java, supports operator overloading.
0 Managed memory is automatically garbage collected. Garbage collection addresses the
problem of memory leaks by freeing the programmer of responsibility for releasing memory
that is no longer needed.
0 C provides properties as syntactic sugar for a common pattern in which a pair of methods,
accessor (getter) and mutator (setter) encapsulate operations on a single attribute of a
class. WHY C ? : FEATURES …cont.
0 In addition to the try...catch construct to handle exceptions, C has
a try...finally construct to guarantee execution of the code in
the finally block, whether an exception occurs or not.
0 Unlike Java, C does not have checked exceptions. This has been a
conscious decision based on the issues of scalability and versionability.
0 Multiple inheritance is not supported, although a class can implement any
number of interfaces. This was a design decision to avoid complication and
simplify architectural requirements throughout CLI.
0 C supports a strict Boolean data type, bool. Statements that take
conditions, such as while and if, require an expression of a type that
implements the true operator, such as the boolean type.
C & OBJECT ORIENTED
(I) Structs & Classes
(IV)Switch Statement: Fall Through
(V) For Each: Control Flow
(VII)Boxing & Unboxing
(VIII)Common Type System
(I) STRUCTS & CLASSES IN C
0 In C structs are very different from classes. Structs in C are designed to
encapsulate lightweight objects. They are value types (not reference types), so
they're passed by value.
0 They are sealed, which means they cannot be derived from or have any base class.
0 Classes in C are different from classes in C++ in the following ways:
i. There is no access modifier on the name of the base class and inheritance is always
ii. A class can only be derived from one base class. If no base class is explicitly
specified, then the class will automatically be derived from System.Object.
iii. In C++, the only types of class members are variables, functions, constructors,
destructors and operator overloads, C also permits delegates, events and
iv. The access modifiers public, private and protected have the same meaning as
in C++ but there are two additional access modifiers available: (a) Internal (b)
0 C does not support Multiple Inheritance
0 However a class can implement number of interfaces
0 It contains methods, properties, indexers, and events
void Bind(IDataBinder bind);
Class EditBox: Control, DataBind
void DataBind.Bind(IDataBinder bind) …
0 A delegate is similar to a function pointer in C/C.
0 Using a delegate allows a programmer to encapsulate a
reference to a method inside a delegate object, which can then
be passed to code.
0 Declaring a delegate:
public delegate void BookDelegate(Book book);
0 Instantiating a delegate:
0 Calling a delegate:
0 In C a switch statement may not "fall through" to the next statement if it does any work.
To accomplish this, you need to use an explicit goto statement:
goto case 5;
If the case statement does not work (has no code within it) then you can fall :
case 4: // fall through
(V)FOR EACH CONTROL
New control flow statement- foreach :
C provides an additional flow control statement, for each. For each loops
across all items in array or collection without requiring explicit specification of
Foreach(double someElement in MyArray)
0 In C one can choose to override a virtual function from base class. Derived
method can participate in polymorphism only if it uses the keyword override before
0 In C++, if provided the same syntax method in derived class as base
class virtual method, it will be automatically be overridden.
0 In C we have abstract methods and in C++ pure virtual methods. Both may not be
exactly same, but are equivalent (as pure virtual can have function body)
public virtual string VirtualMethod()
return "base virtual";
class Derived : Base
public override string VirtualMethod()
return "Derived overriden";
(VII)BOXING AND UNBOXING
0 Boxing is the operation of converting a value-type object into a value of a
corresponding reference type.
0 Boxing in C is implicit.
0 Unboxing is the operation of converting a value of a reference type
(previously boxed) into a value of a value type.
0 Unboxing in C requires an explicit type cast. A boxed object of type T
can only be unboxed to a T (or a nullable T).
0 EXAMPLE :
int box_var = 42; // Value type.
object bar = box_var; // foo is boxed to bar.
int box_var2 = (int)bar; // Unboxed back to value type.
(VIII)COMMON TYPE SYSTEM
0 C has a unified type system. This unified type system is called Common
Type System (CTS).
0 A unified type system implies that all types, including primitives such as
integers, are subclasses of the System.Object class. For example, every type
inherits a ToString() method.
0 CTS separates data types into two categories:
1. Value types
2. Reference types
(VIII)VALUE TYPE V/S
0 Instances of value types do not have referential identity nor referential
comparison semantics i.e. equality and inequality comparisons for value types
compare the actual data values within the instances, unless the corresponding
operators are overloaded.
0 Value types are derived from System.ValueType, always have a default
value, and can always be created and copied.
0 They cannot derive from each other (but can implement interfaces) and
cannot have an explicit default (parameterless) constructor.
(VIII) VALUE TYPE VS
REFERENCE TYPE …cont.
0 Reference types have the notion of referential identity - each instance of a
reference type is inherently distinct from every other instance, even if the
data within both instances is the same.
0 It is not always possible to create an instance of a reference type, nor to
copy an existing instance, or perform a value comparison on two existing
0 Specific reference types can provide services by exposing a public
constructor or implementing a corresponding interface (such
as ICloneable orIComparable). Examples: System.String, System.Array
0 Generics use type parameters, which make it possible to design classes and methods that do not
specify the type used until the class or method is instantiated.
0 The main advantage is that one can use generic type parameters to create classes and methods
that can be used without incurring the cost of runtime casts or boxing operations.
public class GenericListT
void Add(T input)
private class ExampleClass
static void Main()
// Declare a list of type int.
GenericListint list1 = new GenericListint();
// Declare a list of type string.
GenericListstring list2 = new GenericListstring();
0 Reflection is useful in the following situations:
0 When you need to access attributes in your program's metadata. See the
topic Accessing Attributes With Reflection.
0 For examining and instantiating types in an assembly.
0 For building new types at runtime. Use classes
0 For performing late binding, accessing methods on types created at run
// Using GetType to obtain type information:
int i = 42;
System.Type type = i.GetType();