1. static and dynamic attributes in philosophy correspond to attributes and behaviors respectively.
2. Static methods are accessed by class names. Static methods can only access static members. Non-static methods can access all members.
3. Use of attributes and indexer.
4. Access type modifiers: Public, private, protected, and internal.
5. Static members can be used before the object is created.
Example:
Using System;
Public Class CD
{
Public String Name;
Public Double Price;
Public String Type;
Public CD ( String Name, Double Price, String Type)
{ This . Name = Name; This . Price = price;This . Type = type ;}
}
Public Class Videoshop
{
Private CD [] cdset = New CD [ 10000 ];
Private Int Cdcount = 0 ;
Public Int Count {Get { Return This . Cdcount ;}}
// 1. The first index type
Public CD This [ String Cdname]
{
Get
{
Foreach (CD item In Cdset)
If (Item. Name = cdname)
Return Item;
Return Null ;
}
}
// 2. The second index type
Public CD This [ String Cdname, String Type]
{
Get
{
Foreach (CD item In Cdset)
If (Item. Name = cdname & item. type = type)
Return Item;
Return Null ;
}
}
// 3. The third index type
Public CDThis [ Int N]
{
Set
{
If (Cdset [N] = Null ) Cdcount ++;
If (Value = Null & Cdset [N]! = Null ) Cdcount --;
Cdset [N] = value;
}
Get
{
Return Cdset [N];
}
}
}
Class Test
{
[Stathread]
Static Void Main ( String [] ARGs)
{
Videoshop myshop = New Videoshop ();
CD CD1 = New CD ( " Jinling 13-game " , 45 , " DVD " );
CD CD2 = New CD ( " Rome holiday " , 25 , " VCD " );
Myshop [myshop. Count] = CD1;// Call index type 3
Myshop [myshop. Count] = Cd2; // Call index type 3
Cd a = myshop [ " Jinling 13-game " ]; // Call index type 1
Cd B = myshop [ " Rome holiday " , " VCD " ]; // Call index type 2
Console. writeline ( " Name: {0} {1}, price: {2} " , A. type, A. Name, A. Price );
Console. writeline ( " Name: {0} {1}, price: {2} " , B. type, B. Name, B. Price );
Console. Readline ();
}
}