Dot Net School

Dot Net School

Share

Dot Net Advance Tutorial.

10/12/2014

what c #?

-C # is a class based object oriented language.

programing syntax:
c++

main()
{
//code
}
no-error

c #

class Program
{
static void Main()
{
//code
}
}

History:

-in the year of 1999 c # introdued by ANDERS HEJLSBERG and given name as COOL(c like object oriented language)
-in the year 2000 it came to .net platform

Features:

1. It supports OOPs
1. Class and object
2. Absraction
3. Encapsulation
4. Polymorphism
5. Inheritance
6. Property
7. Delegate and Events
8. Namespace
2. It supports CUI and GUI application.
3. It supports WINDOW and WEB-BASED application
4. It supports DRAG AND DROP facilities
5. It Supports MULTITHREADING.
6. It supports CRYSTAL REPORTS.

Class and Object:

-class is a logical structure which contains mf(),datamember,properties etc.
-in c # class is represented by the keyword “class” followed by a valid “class name”

class $abc
{
}
//here it is not a valid class

Rules and Regulation to declare a class name:

1. It must not contains special symbols except underscore (_)
-class _abc{..}[Valid class]
-clas abc*xyz(){..}[invalid class]
2. It must not contain white-space
-class abc vb{..}(invalid)
3. Class name must be started with alphabets(upper case or lowercase) or underscore(_)
4. Class name in c # should be stated from Capital letter.
-class Abc{..}[more valid]
-class abc{..}[less valid]
5. Foe multiword class name the first letter of each word should be started from capital letter.
-class AnimalClass{..}[more valid]
-class animalclass{..}[less valid]

Member of the class:
1. Data member
2. Memberfunction
3. Events
4. Property
class ClassName
{
1. Datamember
2. Mf()
3. Evnts
4. Propery
}
Note:
1. aove stated members can be accessed through object or classname.
2. Due to this members can be stated as either object/instance member or class member.
3. Class member are represented by “static” keyword

class Abc
{
int x;(object)
int y;(object)
static int z;(class)
}

-I wnt to give value to x and y
-so that I must learn learn how to create an object in c #
Note:
1. Object member are accessed by the objectname with a dot(.) operator.
Craeting object:
1. Object can be created in two ways.
2. 1st way:
class Abc
{
int x;
int y;
}
//create an object
Syntax:

Classname objectname;
objectname=new Classname([param]);
ex:
Abc obj;(obj is called class variable)
obj=new Abc();
new-operator which allocates memory for object
Abc()-Default const.
Note:
1. Object are created on const.

2nd way:
Syntax:

Classname objectname=new Classname([parm]);
Ex:
Abc ob=new Abc();

Accessing Object Member:
class Abc
{
int x;//dm
int y;//dm
static void Main()//mf()
{
Abc ob = new Abc();
ob.x = 10;
ob.y = 20;
System.Console.WriteLine("x="+ob.x);
System.Console.WriteLine("y="+ob.y);
System.Console.ReadKey();
}
}

Explanation:

Here x and y can be used by Main() by cereating anobject of Abc class, becoz all are remaining inside the same class i.e-Abc
class Abc
{
int x;
int y;
}
class Demo
{
static void Main()
{
Abc ob = new Abc();
ob.x = 10;
ob.y = 20;
System.Console.ReadKey();
}
}
Explanation:
-errors
'Abc.x' is inaccessible due to its protection level
'Abc.y' is inaccessible due to its protection level

Why these errors?
Ans:Access modifier is not supporting
What is Access Modifieer?
What are Access modifiers?
1. Are the keywords which provide the accessibility level to the members?
2. What is Accessibility level?
C # supports 3 types of accessibility
1. Inside class
2. Outside class
3. Outside assembly.

//diagram

1. Inside class accessibility:
1. Member of this accessibility can only be accessed within the class by the mf(),properties and const of that class.
2. They cannot be accessed directly outside the class by object.
3. Here are the access modifiers are private and protected
4. Note: by default all the members of a class are private.

class Abc
{
int x; //private int x;
}
Abc ob=new Abc();
ob.x=20;(not possible)

ex:
class Abc
{
private int x;
protected int y;
}
class Demo
{
static void Main()
{
Abc ob = new Abc();
ob.x = 10;(X)
ob.y = 20;(X)
System.Console.ReadKey();
}
}
Explanation:
-errors
'Abc.x' is inaccessible due to its protection level
'Abc.y' is inaccessible due to its protection level
Accessing within mf() within a same class:

class Abc
{
int x;
protected int y;
public void SetData()
{
x = 10;
y = 20;
}
public void ShowData()
{
System.Console.WriteLine("x="+x);
System.Console.WriteLine("y="+y);
}
}
class Demo
{
static void Main()
{
Abc ob = new Abc();
ob.SetData();
ob.ShowData();
System.Console.ReadKey();
}
}

ii. Outside class Accessibility:
1. Member of this accessibility can be accessed inside the class by mf(),properties and const and can also be accessed outside the class directly throgh object.
2. Here the access modifiers are public,internal and internal protected.
class Demo
{
public int x;
internal int y;
internal protected int z;
int p;//private member
protected int ip;
static int r;

static void Main()//member funciton
{
//here x,y,z are not visible becoz Main(){} is a static mf() and static mf() can not directly access the non-static dm.
//to access them we will use the object
Demo ob = new Demo();

ob.x = 10;
ob.y = 20;
ob.z = 30;
ob.ip = 40;
ob.p = 50;
r = 70;//here r is visible directly

}
public void MyMethod()
{
//here x ,y,z are visible as MyMethod() is ns mf() and a ns-mf() can access the ns dm direclty
x = 10;
y = 20;
z = 30;
p = 40;
ip = 50;
}
}
Summary:

1. Static mf() can only directly access to the static members(dm,property,mf()) within same class.
2. Static mf() to access ns members use an object.
3. Non-stativ mf() can access static and ns members directly within the same class.
class Demo
{
public int x;
internal int y;
internal protected int z;
int p;//private member
protected int ip;
public static int r;

}
class MyClass
{
static void Main()
{
Demo ob = new Demo();
ob.x = 10;
ob.y = 20;
ob.z = 30;
//ip and p can not be accessible becoz they are protected and private
//to access "r" we will use class name with a dot operator(.)
Demo.r = 40;

}
}

Summary:

1. Member of a class can be access outside the class by objet name with a dot(.) operator when the member are public or internal or internal protected.
2. Static member of a class can be accessed outside the class by the class name with a dot(.) operator when they are public or internal or internal protected.
iii. Outside Assemly or program
what is Assembly?

Ans:
An assembly is a program which represemted by .exe or .dll(Data Link Library).

When .exe is created?

When your program contains Main() after complilation it gives a .exe

namespace Abc
{
class MyClass
{
static void Main()
{
//codes
}
}

}

Here Abc is the name of the program ,after compilation it will give u [Abc.exe]
When .dll is created?

Ans:
When a program does not contain Main() function are generally gives you a .dll file.

In c # ,.dll file are created by ClassLibrary file.
Note:
.dll file are generally used to store the programing essentials(mf(),properties,dm)

namespace xyz
{
class MyDll
{
//mf()
//dm
//properties
}
}
Here after complilation it will give u [xyz.dll]

1. Member of this accessibility can accessed inside the class by mf(),properties and const and out side the class and assembly by object to access ns memmers and by class name to access static members.
2. Here the only access modifier is public.

Xyz.dll

namspace Xyz
{
class MyClass
{
public int x;
public static int y;
int p;
protected int ip;
pulic void CallMe()
{
//codes
}
}
}

Now here I am going to access the members of Xyz.dll in my project/program [Abc.exe]

namespace Abc
{
class Demo
{
static void Main()
{
//Accessible members are
//x,y and CallMe()
//becoz they are public
}
}
}
Creating Xyz.dll
Open VSFileNewProjectDialog Box[LP:C #,MP:Class Library,LP:Name-Xyz]ok

Write the following codes:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Xyz
{
public class MyClass
{
public int x;
public static int y;
int p;
protected int ip;
public void CallMe()
{
System.Console.WriteLine("Hello World");
}

}
}

BuildBuild Solution
To see my xyz.dll, I will search in the following path
E:\Xyz\bin\Debug

Creating Abc.exe
VSfileNewProjectDialog[LP:C #,MP:Console Application,LP:Name-Abc]ok

Solution Explorer(if not present,viewSolution Explorer)Right click on project name(Abc)Add ReferenceBrowseSearch for Xyz.dll in E:\Xyz\bin\DebugSelect the .dllok

Write the following codes:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Xyz;
namespace Abc
{
class Program
{
static void Main(string[] args)
{
MyClass ob = new MyClass();
ob.CallMe();//public mf()
ob.x = 10;//x is nonstatic public dm
MyClass.y = 20;//y is acccessible by class name as it is a public static dm
Console.WriteLine("x="+ob.x);
Console.WriteLine("y="+MyClass.y);
Console.ReadKey();
}
}
}
Then run (f5)

28/11/2014

1.Web user Controls
2.Real time application of Web User Control
3.Web service vs. WCF

28/11/2014

What is
1.session
2.viewstate
3.cookies

27/11/2014

1.What is .Net?
2.Difference between Windows and Web application?
3.What VC #?
4.History of C #.
5.Features of VC #.
6.Datamember
7.Access modifiers
8.Object Creation?
9.Member Function?
10.Property?
11.Constructor?
12.Namespace?
13.Console Class?
14.Write() vs. WriteLine()
15.Read() Vs. ReadLine()
16.ReadKey()

Want your school to be the top-listed School/college in Bhubaneswar?

Click here to claim your Sponsored Listing.

Location

Category

Address


Bhubaneswar