something about c#

derived 派生  ,inherit 继承
Using inheritance
sealed class can not be inherited.
abstract method and class:
an abstract method is an empty method that has no implementation.
an abstract class is a class that contain abstract members,also can contain non-abstract members.
Because the purpose of the  an abstract class is to act a base class, it's not possible to instantiate an abstract class directly,nor can an abstract class be sealed.
The abstract method in the base class can be override in the derived class.

Using polymorphism
In the base class you can define a virtual method which you can altered in the derived classes with override.

Using Arrays
methods: sort,clear,clone,getlength,indexof,lenght
foreach statement
use a arrays as a method parameters   public int sum(params int[] list){...}
Index a object
public class Zoo {
private string[] theAnimals;
public string this[int i] {
get {
return theAnimals[i];
}

set {
theAnimals[i] 
= value;
}

}

public Zoo() {

theAnimals 
= new Animal[100];
}

}

class ZooKeeper {
static void Main(string[] args) {
Zoo myZoo 
= new Zoo();
myZoo[
0= "wwww";
myZoo[
1= "rrrrr";
String str 
= myZoo[1];

}

}


Using Collections(System.Collections)
ArrayList,Queue,Stack,HashTable

Queue.Enqueue  adds an object to the end of the queue.
Queue.Dequeue  remove and return the object at the beginning of the queue

Stack.Push  insert an object at the top of the stack 
Stack.Pop   remove and return the object at the top of the stack
Stack.Count  get the number of the objects contained in a stack

Hashtable
Book techBook = new Book("Inside C#"0735612889);
// 
public Hashtable bookList;
//
bookList.Add(0735612889, techBook);
//
Book b = (Book) bookList[0735612889];
// b’s title is "Inside C#"

Using Interfaces
An interface is in some ways like an abstract class.  However, it provides  no implementation totally. The class that inherits the interface must provide the implementation.
posted @ 2004-09-13 23:20  bluehat  阅读(216)  评论(0)    收藏  举报