You are on page 1of 33

Arithmetic Operators in c#

Operators Description --,++ Unary Negation and Plus *,/,% Multiplication, division, and remainder +,Binary addition and Subtraction

Relational Operators
Operator < > == <= >= != Description Less than Grater than Logical equal to Less than or equal to grater than or equal to Not equal to

Logical Operators
Operator && || ! Meaning AND OR NOT

Value Types Reference Types Value Types: Boolean Single Byte Double Int16 Decimal Int32 DateTime Int64 Char

Different Data Types in C#

Reference Types: String Array Delegate Class

Class

Class is concrete representation of an entity which h olds attributes and behavior .It Provides Abstraction and Encapsulation

Public ClassA { int i=1; public method1() { //Implimentaion } }

Object

Object Represents real-time entity. An Object simply something you can give a name CalssA obj1 = new ClassA();

Encapsulation and Abstraction

Encapsulation: Encapsulation is a binding of attributes and behaviors. Hiding the actual implementation and expose the functionality of object Encapsulation is a first sep towards OOPs. Is the procedure of covering the up data and functionality into single unit (called class). Its main aim is to protect data from outside world.

Abstraction

Hiding the Complex . It is a process of defining communication interface for the functionality and hiding rest of the things.

Calss zzz { static void main () { System.Console.WriteLine( Hello) } }

if statement
Class zzz { statis void main () { If(false) System.Console.WriteLine(Hello); else System.Console.WriteLine(Bye); } }

For loop
Class zzz { statis void main () { int I; for(i=1;i<=5;i++) { System.Console.WriteLine(HI,i); } }

While loop
Class zzz { statis void main () { int i=i; while(i<=5) { System.Console.WriteLine(HI,i); i++; } }

Modifiers

Private: Access limit to the current class. Public: All members have access in all classes and projects. Protected: Access limit to the containing class or types derived from the containing class. Internal : Access limit to the current assembly. Protected Internal: Access limit to the current assembly or type derived from the containing class

Public
Class zzz { Public static void main() { yyy.pqr(); } } Class yyy { Static void abc() { System.console.writeLine(yyy abc); } Public static void pqr() { System.console.writeLine(yyy pqr); abc(); } }

Modifier

Private Modifier
Class zzz { Public static void main() { yyy.abc(); } } Class yyy { Static void abc() { System.console.writeLine(yyy abc); } public static void pqr() { System.console.writeLine(yyy pqr); abc(); } }

Protected Modifier
Class zzz { Public static void main() { yyy.abc(); } } Class yyy { Protectd Static void abc() { System.console.writeLine(yyy abc); } Public static void pqr() { System.console.writeLine(yyy pqr); abc(); } }

Calling Methods
Class zzz { statis void main () { zzz.abc(); abc(); yyy.abc(); } Public static void abc() { System.Console.wrtiteLine(abc); } } Class yyy { Public static void abc() { System.Console.wrtiteLine(abc); } }

Inheritance

One Object acquire the properties of another object.

Class zzz { public statis void main () { xxx a = new xxx(); a.abc(); } } Public class yyy { Public int i=10; Public void abc(); { System.Console.wrtiteLine(yyy abc); } public void pqr() { System.Console.wrtiteLine(yyy pqr); } } Class xxx:yyy { Public void abc() { System.Console.writeline(xxx abc); Base.abc(); } }

Polymorphism
More than one form ,ability to provide different implementation Class zzz { Public static void main() { yyy a = new yyy(); a.abc(10); a.abc(hello) a.abc(bye,100); } }

Class yyy { Public void abc(int i) { System.console.WriteLine(abc+i); } Public void abc(string s) { System.console.WriteLine(abc+s); } Public void abc(string s,int i) { System.console.WriteLine(abc+s +i); } }

Constructors
constructor always called whenever a instance of the class is created. Class zzz { statis void main () { yyy a= new yyy(); } } Class yyy { Public yyy() { System.Console.wrtiteLine(yyy); } }

Constructors with parameters


Class zzz { statis void main () { yyy a= new yyy(hi); } } Class yyy { Public yyy(string s) { System.Console.wrtiteLine(s); } }

Static Constructors

Static constructor of a class is executed just before any instance of the class is created. Static constructor of a class is executed just before any static member of the class is referenced.

Class test { Static void main() { A.F(); B.F(); } } Class A { Static A() { Console.WriteLine(Init A); } Public static void F() { Console.WriteLine(A.F); } } Class B { Staic B() { Console.WriteLine(Int B); } Public static void F() { Console.WriteLine(B.F); } }

Destructors
A special method called by GC. Just before object is being reclaimed by GC Class zzz { statis void main () { aa a = new aa(); } } Public class aa { Public aa() { System.Console.wrtiteLine(constructor); } ~aa() { System.Console.wrtiteLine(distructor); } }

Abstract Class
Public class zzz { Public static void main() { New bbb(); } }

Abstract class aaa { Abstract public void pqr(); Public int I; Public void abc() { } } Class bbb: aaa { Public override void pqr() { System.Console.writeLine(bbb pqr); } }

Virtual Method Virtual Method has an implementation and option to override in the derived class new Method Hiding the base class Method by declaring a method in derived class. Class zzz { Public static void main() { Yyy a = new yyy(); Xxx b = new xxx(); Yyy c = new yyy(); a.abc();a.pqr;a.xyz(); b.abc();b.pqr();b.xyz(); c.abc();c.pqr();c.xyz(); } }

Class yyy { Public virtual void abc() { System.Console.writeLine(yyy abc); } Public virtual void pqr() { System.Console.writeLine(yyy pqr); } Public virtual void xyz() { System.Console.writeLine(yyy xyz); } }

Class xxx: yyy {

Public override void abc() { System.Console.writeLine(xxx abc); } Public new void pqr() { System.Console.writeLine(xxx pqr); } Public void xyz() { System.Console.writeLine(xxx xyz); }

Out Put Yyy abc Yyy pqr Yyy xyz xxx abc xxx pqr xxx xyz xxx abc Yyy pqr Yyy xyz

Sealed Method
Sealed classes are those classes which can not be inherited and thus any sealed class member can not be derived in any other class.

You might also like