Reference Types
Reference ဆိုတာ နားလည္ေအာင္ေတြးၾကည့္မယ္ဆိုရင္ေတာ႔ ကိုယ္စားလွယ္ေပါ႔ ။ အဓိကပု ဂၢိဳလ္ ကိုယ္တိုင္ ပါဝင္ဖို႔မျဖစ္နိုင္တဲ႔ အခါမ်ဳိးမွာ ကိုယ္စားလွယ္လႊတ္သလိုမ်ိဳးေပါ႔ ။ ကိုယ္က ပရိုဂရမ္ထဲမွာ
Value type ေတြကိုတုိက္ရိုက္သံုးလို႔မရနိုင္တဲ႔အခါမ်ိဳးမွာ သူ႔အစား reference ကိုေခၚသံုးတာေပါ႔ ။
သူက value type မဟုတ္တဲ႔အတြက္ တကယ္႔ data မဟုတ္ဘူးဆိုတာ နားလည္ပါ ။ သူ႔က heap ထဲမွာရွိတယ္ မသံုးတာၾကာတဲ႔အခါမွာ garbage collection ကေန အလိုလိုျဖတ္ေပးသြားပါတယ္။
Reference types keywords (6) မ်ိဳးရွိပါတယ္ ။ အဲဒါေတြကေတာ႔ -
Class , interface ,delegate,dynamic,object,string တို႔ပဲျဖစ္ပါတယ္ ။ dynamic,object,string
၃ မ်ိဳးကေတာ႔ built-in reference types ေတြပါ ။
(၁) class
Keyword class ကိုေတာ႔ classes ေတြ ေၾကျငာရမွာသံုးပါတယ္ ။
ဥပမာ
class TestClass
{
// Methods, properties, fields, events, delegates
// and nested classes go here.
}
Class တစ္ခုမွာဆိုရင္ ေအာက္ပါ class members ေတြပါဝင္နိုင္ပါတယ္ ။
Constructors , destructors , constants , fields , Methods , Properties , indexers , operators ,events , delegates , classes , interfaces , structs .
Example
class Child
{
private int age;
private string name;
// Default constructor:
public Child()
{
name = "N/A";
}
// Constructor:
public Child(string name, int age)
{
this.name = name;
this.age = age;
}
// Printing method:
public void PrintChild()
{
Console.WriteLine("{0}, {1} years old.", name, age);
}
}
class StringTest
{
static void Main()
{
// Create objects by using the new operator:
Child child1 = new Child("Craig", 11);
Child child2 = new Child("Sally", 10);
// Create an object using the default constructor:
Child child3 = new Child();
// Display results:
Console.Write("Child #1: ");
child1.PrintChild();
Console.Write("Child #2: ");
child2.PrintChild();
Console.Write("Child #3: ");
child3.PrintChild();
}
}
/* Output:
Child #1: Craig, 11 years old.
Child #2: Sally, 10 years old.
Child #3: N/A, 0 years old.
*/
ဆက္လက္ေရးသားပါမည္ ............။
C#,Keywordsမ်ား(၃)
Thursday, July 1, 2010
Subscribe to:
Post Comments (Atom)
1 comments:
အရမ္းေကာင္းပါတယ္...language တစ္ခုရဲ ့အေျခခံထက္ ဘယ္ language မွာမဆုိ လုပ္လုိ ့ရမယ့္ပံုစံမ်ိဳးကိုေျပာရင္ ပိုေကာင္းမယ္လုိ ့ထင္ပါတယ္ခင္ဗ်ာ..
Read more: http://www.knowledgewar07.com/2009/11/auther-comments-highlight.html#ixzz0s2vyA5Yfေလးစားစြာျဖင့္ပါ...
Post a Comment