Hate it or love it the underdog's on top And I'm gonna shine homie until my heart stop.. About Programming languages,Spain and my life :)
четверг, 9 сентября 2010 г.
понедельник, 19 апреля 2010 г.
C# Interface
It's my first short tutorial.
How to use C# interface with class.
An interface contains only the signatures of methods, delegates or events.
Interfacae - its a rule,which describe a class.
For example:
How to use it.. ? :)
Q:How can I call second class from first class?
A:Its very easy,in first class you should write a classs an alias.
You can use it anywhere in class :)
Like this.
That's all!
It's my first blog in english. :) Please comment it:)
How to use C# interface with class.
An interface contains only the signatures of methods, delegates or events.
Interfacae - its a rule,which describe a class.
For example:
//Our interface name is : ILexSource
interface ILexSource
{
int CurrentLexValue { get; set; }// Set and get? what is it? how to use it? :)
}
class scaner : ILexSource
{
private ICharacterSource source;
public scaner(CharacterSource source)
{
this.source = source;
}
//Method which has the same name as class is called - "CONSTRUCTOR"
What is it constructor? - When you are calling an instance,class automaticly calling a constructor :)
//SECOND INTERFACE
public interface ICharacterSource
{
void nextChar(); //Void it's a procedure,without a return type.
}
class CharacterSource : ICharacterSource
{
string mainString; //our test string
public CharacterSource(string str)
{
this.mainString = str;
}
public void nextChar()
{
Console.Write("YEAS I DID IT!);
}
}
How to use it.. ? :)
scaner Comp = new scaner(new CharacterSource(str); //here we are
Q:How can I call second class from first class?
A:Its very easy,in first class you should write a classs an alias.
private ICharacterSource source;
You can use it anywhere in class :)
Like this.
Source.nextChar(); //YEAS I DID IT!
That's all!
It's my first blog in english. :) Please comment it:)
Подписаться на:
Сообщения (Atom)