Overloading of Indexers
พัชราพร ภายไธสง 650710836
Sysntax
public int this[int index]{
set{//(ใช้สำหรับดึงข้อมูล)
//code
}
get{//(ใช้สำหรับเก็บข้อมูล)
//code
}
}Exemple 1
using System;
namespace Store{
public class Dessert{
private string[] ListDessert = new string[2];
public string this[int index]{
get{
return ListDessert[index];
}
set{
ListDessert[index] = value;
}
}
public string this[double index]{
get{
return ListDessert[1];
}
set{
ListDessert[1] = value;
}
}
static void Main(string[] args){
Dessert collection = new Dessert();
collection[0] = "Cake";
collection[1.0] = "Donut";
Console.WriteLine(collection[1.0]+" "+collection[0]);
}
}
}
อธิบายตัวอย่างที่ 1
Exemple 2
อธิบายตัวอย่างที่2
เปรียบเทียบOverloading of Indexers กับ Java, C, Python
1.ภาษา Java
2.ภาษา Python
3.ภาษา C
Out put
Slide
Reference
Last updated


