Showing posts with label C# Tutorials. Show all posts
Showing posts with label C# Tutorials. Show all posts

Sunday, 3 February 2013

Delegate


Delegate is similar to interface,but the main difference between delegates and interface is delegate created at runtime whereas interface created at compile time.Delegate is also called as safe  function pointers.Or a simple definition of delegate is function which call another function.

Syntax includes:-

->Declaration
->Instantiation
->Method define
->Invocation

Now we take an example:-

Delegate in c #(c sharp),java calls more than one function.

namespace console application 23
{
delegate int multiply-divide(int x,int y)
class md
{
public static int multiply(int a,int b)
{
return(a*b);
}
public static int divide(int a,int b)
{
return(a-b);
}
}
class program
{
static void main(string[],agrs)
{
multiply-divide obj=new multiply-divide(md.multiply);
multiply-divide obj1=new multiply-divide(md.divide);
int ret1=obj(12,55);
int ret2=obj1(30,10);
Console.WriteLine(+ret1);
Console.WriteLine(+ret2);
Console.Read();
}
}
}

That's all about Delegate and its definition(meaning,means).If you have any query then leave your comments and don't forgot to follow me on Google+,Facebook,Twitter.


Saturday, 2 February 2013

Sealed Class and its Method


Sealed class are those class which can not be treated as sub class or child class.Sealed class can not be abstract classes.It is used in c sharp,java etc.

Syntax:-

sealed class xyz
{
.
.

.
.
}

Sealed Method:-Sealed method are the methods which are widely used in c#,java etc.It is used to override virtual function with the same signature.

Example:-

class X
{
public  virtual void function()
.
.
.
}
}
class Y:X
{
public sealed override void function()
{
.
.
.
}
}
class Z:Y

{
public sealed override void function()
{
.
.
.
}
}



If you have any query then leave your comments and don't forgot to follow me on Google+,Facebook,Twitter.

Abstract Method(In short)


Abstract Method are the methods of the abstract class.Abstract method is only declare in abstract class.It can't take static and virtual modifier.It can be override.Abstract Method is used in c sharp(c#),java etc.

Syntax:-

class<Name of Class>:Function
{
override public void function()
{
.
.
}
}

If you have any query then leave your comments and don't forgot to follow me on Google+,Facebook,Twitter.

Abstract Class


Abstract Class is the special class which is widely used in java,c sharp(c#) etc.If we want to made abstract class in our program then we declared keyword abstract before class name.Abstract class support the concept of inheritance.

Syntax:-

abstract<Name of Class>
{
.............
.............
.............
}
Functions-1();
Functions-2();
Functions-3();
}

Example (In c #):-

abstract class student
{
public abstract void read();
public abstract void write();
public abstract void show();
}
class student:student
{
........
........
........
}
.
.
.
(SAME AS OTHER CLASS)
.
.
.
class program
{
static void main(......)
{
Object Creation;
Function Calling;
}
}


That's all about Abstract base Classes.If you have any query then leave your comments and don't forgot to follow me on Google+,Facebook,Twitter.

Thursday, 31 January 2013

Static Constructor in C ++ and C Sharp(C#)(In Short)


Static Constructors are those constructor which are used to initialise static data member of the class.One class has only one static constructor and static constructor always declare in a class.Static constructor is neither parametrised nor copied(Its always default).It is used in C ++,java,c# etc.

Related Posts:-

1)Constructor
2)Default Constructor
3)Parameterized Constructor
4)Copy Constructor
5)Destructor


If you have any query then leave your comments and don't forgot to follow me on Google+,Facebook,Twitter.

Destructor


Destructor:-Destructor is the member function of the class whose work is to destroyed the object that was created by constructor.

Important Properties/characteristics of Destructors:-


1)It always declare in public.


2)Destructor name is same as name of class.


3)Proceed with ~(tiled) sign.


4)It is the member function of class.


5)It has no parameter.


6)It is used to de-allocate the memory.


7)Destrcutor Overloading is not possible.


9)Destructor concept used in many languages like c ++(c plus plus),java,c#(c sharp) etc.


Example of Destructor(in c++):-Now I explain destructor example in c++ but you can also creat it with c sharp(#)(in place of cout puts Console.WriteLine and in place of cin puts Console.ReadLine) as same as like java(But some concept are different).



class stud

{
int stud-id;
public:
stud()
{
stud-id=1;
}
void show()
{
cout<<stud-id;
}
~stud()
{
cout<<"I AM DESTRUCTOR";
}};



If you have any query then leave your comments and don't forgot to follow me on Google+,Facebook,Twitter.

Wednesday, 30 January 2013

Function in C sharp


Functions in C sharp(c#):-Function is a code which perform a specific task.Function are generally divided into 2 parts namely Returning function and non-returning function.

1)Non-Returning Function:-Non-Returning function are those function which are not return a single value.Non-Returning Function are further divided in to two parts namely With Argument and Without Argument.

Example of With Argument:-


void add(int a,int b);

int a,b;
a=Console.WL();
b=Console.WL();
add(a,b);
}
static void add(int a,int b)
{
int c;
c=a+b;
Console.WL(+c);
}}

Example Without Argument:-


void add()
{
add();
}
static void add(int a,int b)
{
int a,b,c;
a=Console.WL();
b=Console.WL();

c=a+b;
Console.WL(+c);
}}


2)Returning Function:-Returning function are those function which are return values.Returning Function are further divided in to two parts namely With Argument and Without Argument as like as Non-Returning function.



If you have any query then leave your comments and don't forgot to follow me on Google+,Facebook,Twitter.

Parameterized Constructor


Parameterized Constructor:-Parametrised Constructor are the constructor that have more than one argument.It is used in c ++,java,c#(c sharp) etc.

Example of Parametrised Constructor(in c++):-

#include<iostream.h>
#include<conio.h>
class number
{
int x,y,z;
public:
number(int a,int b)   
{
x=a;
y=b;
}
void sum()
{
z=x+y;
cout<<z;
}};
void main()
{
class no(20,30);        //object
clrscr();
no.sum();
getch();
}



If you have any query then leave your comments and don't forgot to follow me on Google+,Facebook,Twitter.

Copy Constructor


Copy Constructor:-Copy Constructor are the constructor that have one argument of the object of same class.Copy constructor is used in c ++,java,c#(c sharp) etc.

Example of Copy Constructors(in c++):-

#include<iostream.h>
#include<conio.h>
class number
{
int a,b;
public:
number(int x,int y)     
{
a=x;
b=y;
}
number(number &n)    //copy constructor 
{
a=m;
b=m.b;
}
void display()
{
cout<<a<<b;
}};
void main()
{
number m(20,49);
m.display();
number m1(m);
m1.display();
getch();
}



If you have any query then leave your comments and don't forgot to follow me on Google+,Facebook,Twitter.

Default Constructor


Default Constructor:-Default Constructor are the constructor that accept no parameter or 0 parameter.Default constructor is used in c ++,java,c#(c sharp) etc.

Example of Default Constructors(in c++):-

#include<iostream.h>
#include<conio.h>
class swap
{
int x,y;
public:
swap()          //default constructor
{
x=10;
y=20;
}
void swap()
{
x=x+y;
y=x-y;
x=x-y;
cout<<x<<y;
}};
void main()
{
class sw;        //object
clrscr();
sw.swap();
getch();
}


If you have any query then leave your comments and don't forgot to follow me on Google+,Facebook,Twitter.


Constructors


Constructor:-Constructor is the member function of the class whose work is to initialised objects.

Important Properties/characteristics of Constructor:-


1)Constructor declare in public section.


2)Constructor don't have return type.


3)Constructor can not be virtual type.


4)Constructor is used to allocate memory for variables.


5)Constructor is member function of class.


6)Constructor name is same as name of class.


7)Class may have more than 2 Constructor.


8)Constructor may be parametrised and copied.


9)Constructor concept used in many languages like c ++(c plus plus),java,c#(c sharp) etc.


Type of Constructor:-


1)Default Constructor.

2)Copy Constructor.
3)Parameterized Constructor.

Example of Constructor(in c++):-I explain Constructor example in c++ but you can also created it with c sharp(#)(in place of cout puts Console.WriteLine and in place of cin puts Console.ReadLine) as same as like java.(But some concept are different)


#include<iostream.h>

#include<conio.h>
class number
{
int x,y,z;
public:
number()   
{
x=20;
y=40;
}
void sum()
{
z=x+y;
cout<<z;
}};
void main()
{
class no;        //object
clrscr();
no.sum();
getch();
}


If you have any query then leave your comments and don't forgot to follow me on Google+,Facebook,Twitter.

Tuesday, 29 January 2013

Structure in C Sharp


Structure in C#:-Structure is the collection of different type of element or heterogeneous element.

Condition's of data structure in C#:-

1)It is value type in c#.

2)Its memory allocation is static.

3)Initial Value is always 0.

4)All member are private(by defaults).

5)We can declare constructor in it.

Structure Example:-

struct book
{
public int r,p;
public string a,n;
public void read()
{
Console.WL("Enter book rate");
r=Convert.ToInt32(Console.ReadLine());
Console.WL('Enter pages");
p=Convert.ToInt32(Console.ReadLine());
Console.WL("Author name");
a=Console.ReadLine();

Console.WL("Name of book");
b=Console.ReadLine();
}
Public void write()
{
Console.WL("book rate="+r);
Console.WL('pages="+p);
Console.WL("Author name="+a);

Console.WL("Name of book="+n);
}
}
class program
{
static void main()
{
book bo;
bo.read();
bo.write();
}
}
}


If you have any query then leave your comments and don't forgot to follow me on Google+,Facebook,Twitter.

String in C Sharp


String Manipulation in C#:-String is also called as array of character.Each string is terminated by null character represented by '/0'.String is the predefined data type in C#.We write object as 'System.String'

Some String Methods/Properties:-

1)Assignation:-

string st1;
s1="xyz";

2)Copy 2 strings:-

string st1=st2;
string st2=String.Copy(st1);

3)Concatenate 2 string:-


string st3=st1+st2;
string st3=String.Concat(st1,st2);

4)Compare two string:-

int number=String.Compare(st1,st2);
 then,
if(String.Compare(st1,st2)==0)
then,
PRINT

5)Join():-Join method is used to join two strings.

6)Remove():-Remove function is used to delete character from string.

7)Equals():-Is used to check the equality of 2 string.

8)Insert():-Insert is used to insert a  string at a specified location.

9)ToLower():-Is used to "Returns lower case of the string".

10)ToUpper():-Is used to "Returns Upper case of the string".



If you have any query then leave your comments and don't forgot to follow me on Google+,Facebook,Twitter.

Array in C sharp


Arrays in C Sharp:-Array is the collection of similar type of element.

Declaration of Array in C#:-

[data type][[]][array name]=[no. of array element]

Example:-int[]ar=[3,5,6,7,8];

Array index always start from 0 to n-1.Array can be access randomly.

System.Array Class:-The array methods are as follows:-

1)Clear()  2)CopyTo()  3)GetLength()  4)Length()  5)SetValue()  6)Reverse()  7)Sort()  8)Add()  9)CopyTo()  10)Insert()  11)Remove()  12)RemoveAt()  13)Sort()  14)Capacity()  15)Count()  etc.

Program of C# using Array:-


int[]ar=[2,5,6,3,1,4,88];

int s,t=0,1;
double ar;
s=ar.length;
for(i=0;i<s;i++)
{
t=t+ar[i];
Console.Writeline(ar[i]);
}
ar=t/s;
Console.Writeline("Average="+ar);
Console.Read();
}
}
}

If you have any query then leave your comments and don't forgot to follow me on Google+,Facebook,Twitter.

What is C Sharp(C#)


C Sharp or C# is the programming language which is used to create software/applications.C# run in .(dot) Environment.This language is introduce by Microsoft Corp.The Extension of c# is .cs.

C# Programming Example(s):-


P:class My-Name
 {

static void Main()
{
System.Console.write Line("My Name is John");
}
}


P:class My-Middle-Name
{
static void Main()
{
System.Console.write Line("My Middle Name is Kumar");
}
}



P:class My-Last-Name

{
static void Main()
{
System.Console.write Line("My Last Name is White");
}
}


C# is object oriented language,it support all concept of oops like object,class,inheritance,encapsulation,
abstraction etc.

C# contains namespaces(collection of classes).C# is very much case sensitive.


This is the Introduction of c sharp.If you have any query then leave your comments and don't forgot to follow me on Google+,Facebook,Twitter.