Windows Phone Developers

Wednesday, October 22, 2008

How to Create Classes in C#

C# Class Examples

A class can be created using the class keyword. A class can contain properties, variables, constants, events, methods, constructors, structs etc.

class ClsTea

{

//Variables

private string _locale;

private static string _brand;

// Property

public static string Brand

{

get

{

return _brand;

}

set

{

_brand = value;

}

}

//property

public string Locale

{

get { return _locale; }

set { _locale = value; }

}

private string[] brands = new string[12];

public string this[int index]

{

get { return brands[index]; }

set { brands[index] = value; }

}

}

A class can inherit implementation from one base class only. For example, ClsTea can Inherit from Class Beverages

class ClsTea : Beverages

A class can, however, implement more than one interface

Inheritance

Example

None

class ClsTea { }

Single

class ClsTea : Beverages { }

None, implements two interfaces

class ClsTea: IProduct, IRetail { }

Single, implements one interface

class ClsTea : Beverages, IRetail { }

Digg Technorati Delicious StumbleUpon Reddit BlinkList Furl Mixx Facebook Google Bookmark Yahoo
ma.gnolia squidoo newsvine live netscape tailrank mister-wong blogmarks slashdot spurl StumbleUpon

No comments:

Post a Comment