Programming Manual for C#

Programming Manual for C#

Trainer: Mr. C.Santhosh Kumar, 329469

INDEX

S.No

Topics

1

Basic concepts of C#

2

Control flow constructs and Looping

3

Parameter Types in C#

4

Arrays in C#

5

Constructors and Destructors

6

Structures members and classes

7

Enumerations

8

OOPs Concepts

9

Polymorphism

10

Inheritance

11

Abstract Class

12

Interface

13

Partial Class

14

Properties & Indexers

15

Collections

16

Exception Handling in C#

17

File Handling in C#

18

XML with C#

19

Delegates and Events

20

Reflection

21

Serialization

22

Multi-Threading

23

LINQ

24

DotNet InterOperability

25

Web Services

26

Extension Methods in C#

Page Numbers

1 5 10 14 20 25 28 30 34 41 46 50 54 56 63 83 88 97 107 122 146 157 169 192 194 198

? LENAPRASANNA MANI, 346238

1|Page

1.Basic Concepts Of C#

Structure of C# program:

Classes are main blocks of a C# program. A program in C# may contain many classes of which only one class defines a main method. Classes contain data members and methods that operate on the data members of the class. Methods may contain data type declaration and executable statements. To write a C# program, we first define a class and then put them together. A C# program may contain one or more sections as given below

o Documentation Section It is a best Suggested practice to include them

o Import Library Files(using) It is Optional

o Namespace,Class and Type definitions Essential (atleast one class containing main method)

Basic syntax of a C# Program is given below:

using namespaces;

namespace projectName {

class class_name1 {

..... } class class_name2 {

..... }

.... class class_nameN {

..... } }

? LENAPRASANNA MANI, 346238

2|Page

Datatypes:

There are three main categories in datatypes.

Value types Reference types Implicitly typed local variable (var)

Let us see what are all the datatypes available in each types.

a)Value types:

Predefined types:

(a) Numeric types: (i) Integer 1) Signed int a) Sbyte (8 bit signed int) b) Short(16 bit signed int) c) Int (32 bit signed int) d) Long (64 bit signed int) 2) Unsigned int a) Byte (8 bit unsigned int) b) Ushort (16 bit unsigned int) c) Uint (32 bit unsigned int) d) Ulong (64 bit unsigned int) (ii) Float

(iii) Double (b) Char (c) Decimal (d) Boolean

True False

User defined types:

1) Struct 2) Enum

b) Reference type:

Predefined types:

1) String 2) Object

? LENAPRASANNA MANI, 346238

3|Page

User defined types:

1) Array 2) Classes 3) Interfaces 4) List 5) Array list 6) Stack 7) Hash table 8) Queue

And so on.. Note: Value types are stored in stack memory and reference types are stored in Heap memory in C#.

Type Conversion:

There are 2 types of conversion available in C#.

a)Using Conversion functions a. Convert.ToInt32() - converts values to integer b. Convert.ToDouble()- converts values to double c. Convert.ToSingle()- converts values to float d. Convert.ToDecimal()- converts values to decimal

b)Using parser methods a. int.parse() b. float.parse() c. double.parse()

and so on...

Implicit and explicit type conversion:

a) Implicit Type Conversion:

Conversion from value type variables to reference type variable is called Boxing (Implicit type conversion).

Example: Boxing

int i=10; object Obj; Obj=i; //Implicit type conversion occurs from integer type to object type

? LENAPRASANNA MANI, 346238

................
................

In order to avoid copyright disputes, this page is only a partial summary.

Google Online Preview   Download