User - Defined Datatype in C#
1.Enumeration:-
Defining:-
enum TrafficLight
{
Red,
Green,
Yellow
};
Declaration:-
TrafficLight tl;
Assigning:-
tl = TrafficLight.Yellow Or
tl =(TrafficLight) 2;
By default they begin with value 0 associated. while we can set this bound value explicitly.
---------------------------------------------------------------------------------------
2.Class
Access Modifier:-They enforce encapsulation concept of OOP.
------------------
Constant Vs. ReadOnly Fields:-
Constant are constant throughout the application and their value must be known at the time of compilation , and can not be alter during lifetime of the project.They act like a static field.
While ReadOnly field can be assigned at the the time time of declaration or in constructor , so they will be assigned at the execution time, then their value can not be alter thereafter.They are class level variable.
Ex:-
const int a=10;
readonly a = 10;
--------------------------------------------------------------------------------------
Static class
They Do not have constructor(Other than static).
So Their object can not be created.
They are sealed , hence no Inheritance mechanism take place;
Static class indicate that their member are also static.
-------------------------------------------------------------------------------------
Variable:-
local variable can not be define as public , protected,or private.
-------------------------------------------------------------------------------------
Indexer:-
-They allow us to use a class as a virtual array and enables object to be accessed by using index;
Access Modifier:- Can be Private,Public,Protected,Internal
Return type:-Any C# Valid type;
Arguments:-Must have at least one parameter,they may have multiple parameter of different type;
-All indexers in the same class must have different signatures;
-Get,set are known as accessor ,their visibility is same as the visibility of indexer by default.the accessibility of set can be set explicitly.
-operator [] is used to access indexer.
-They can be inherit.
-They can be override.
-Can be abstract(with no code in set,get)
-Can NOT be static.
---------------------------------------------------------------------------------
Interface:
-Object Can Not be created;
ex:-
public interface IMyFirst
{
void PrintMe():
}
public interface IMySecond
{
void PrintMe():
}
class Program : IMyFirst, IMySecond
{
void IMyFirst.PrintMe()
{
Console.WriteLine("Channel Next");
}
void IMySecond.PrintMe()
{
Console.WriteLine("Book Next");
}
static void Main(string[] args)
{
Program obj= new Program();
((IMyFirst)obj).PrintMe();
((IMySecond)obj).PrintMe();
}
}
- The example demonstrate how we can differentiate b/w the same method in different interface.
----------------------------------------------------------------------------------
Thanks & Regards
Bheeshma P. Nayak
1 comment:
hey,
gud yar... its like u have created a new book on .Net....
Post a Comment