C# හි compiler එකට (සම්පාදකයාට) විශේෂ අරුතක් ඇති වෙන් කළ වචන අඩංගු වේ. මෙම වෙන් කර ඇති වචන “Keywords” ලෙස හැඳින්වේ. විචල්ය නොහොත් variables , class, Interfaces යනාදී හි නම් සඳහා වචන identifies(හඳුනාගැනීමක්) ලෙස Keywords භාවිතා කළ නොහැක.
කලින් කොටස් සඳහා යෑමට
C# Programming සරලව සිංහලෙන් – 1 කොටස හැදින්වීම
C# Programming සරලව සිංහලෙන් – 2 කොටස – පරිගණකයේ සංවර්ධන පරිසරය සැකසීම
C # හි keywords පහත දැක්වෙන කාණ්ඩ යටතේ බෙදා හරිනු ලැබේ:
Modifier Keywords (විකරණකාරක පද)
Modifier keywords යනු modify types සහ member types කළ හැක්කේ කාටද යන්න පෙන්වන ඇතැම් මූල පද වේ. Programmes වල සමහර කොටස් වෙනත් කොටස් විසින් වෙනස් කිරීම modifiers විසින් ඉඩ ලබා දේ.
Modifier keywords |
---|
abstract |
async |
const |
event |
extern |
new |
override |
partial |
readonly |
sealed |
static |
unsafe |
virtual |
volatile |
Access Modifier Keywords (ප්රවේශ විකරණකාරක මූල පද)
class, method, properties, fields සහ අනෙකුත් member ප්රකාශය මත ප්රවේශ විකරණකාරක යොදනු ලැබේ. ඔවුන් පන්තියේ (class) සහ එහි සාමාජිකයන්ගේ (members) ප්රවේශ්යතාව නිර්වචනය කරයි.
Access Modifiers | Usage |
---|---|
public | The Public modifier allows any part of the program in the same assembly or another assembly to access the type and its members. |
private | The Private modifier restricts other parts of the program from accessing the type and its members. Only code in the same class or struct can access it. |
internal | The Internal modifier allows other program code in the same assembly to access the type or its members. This is default access modifiers if no modifier is specified. |
protected | The Protected modifier allows codes in the same class or a class that derives from that class to access the type or its members. |
Statement Keywords (ප්රකාශන මූල පද)
ප්රකාශන මූල පද වැඩසටහන් ප්රවාහයට (flow control) සම්බන්ධ වේ.
Statement Keywords |
---|
if |
else |
switch |
case |
do |
for |
foreach |
in |
while |
break |
continue |
default |
goto |
return |
yield |
throw |
try |
catch |
finally |
checked |
unchecked |
fixed |
lock |
Method Parameter Keywords (ක්රම පරාමිති මූල පද)
Method parameter මත මෙම keyword යොදනු ලැබේ.
Method Parameter Keywords |
---|
params |
ref |
out |
Namespace Keywords (නාම අවකාශයේ පද)
මෙම Keywords, namespace හා operators සමඟ යොදනු ලැබේ.
Namespace Keywords |
---|
using |
. operator |
:: operator |
extern alias |
Operator Keywords
Operator keywords විවිධ ක්රියා සිදු කරයි.
Operator Keywords |
---|
as |
await |
is |
new |
sizeof |
typeof |
stackalloc |
checked |
unchecked |
Access Keywords
Object හෝ class එකක අඩංගු class එක හෝ base class එක වෙත ප්රවේශ වීමට Access keywords භාවිතා කරයි.
Access keywords |
---|
base |
this |
Literal Keywords
වචනයේ පරිසමාප්ත අර්ථයෙන්ම object එකක වර්තමාන අවස්ථාව හෝ value එකට අදාළ වේ.
Literal Keywords |
---|
null |
false |
true |
value |
void |
Type Keywords
දත්ත වර්ග සඳහා keywords භාවිතා වේ.
Type keywords |
---|
bool |
byte |
char |
class |
decimal |
double |
enum |
float |
int |
long |
sbyte |
short |
string |
struct |
uint |
ulong |
ushort |
Contextual Keywords
Constextual keywords ලෙස සලකනු ලබන්නේ ඇතැම් context සඳහා භාවිතා කරන්නේ නම් පමණි. ඒවා වෙන් කර නොමැති අතර ඒවා names හෝ identifiers ලෙස භාවිතා කළ හැකිය.
Contextual Keywords |
---|
add |
var |
dynamic |
global |
set |
value |
විෂුවල් ස්ටුඩියෝ identifiers භාවිතා කරන විට Contextual keywords නිල් වර්ණයට පරිවර්තනය නොවේ. උදාහරණයක් ලෙස, පහත රූපයේ var නිල් වර්ණයෙන් නොපවතින අතර මෙහි වර්ණය නිල් පැහැය වේ. එබැවින් var යනු Contextual keyword එකකි.
ඉහත සඳහන් කළ පරිදි, keywords, identifier ලෙස භාවිතා කළ නොහැක (variable names, classes, interfaces යනාදිය). කෙසේ වෙතත්, ඒවා ‘@’ උපසර්ගය (prefix) සමඟ භාවිතා කළ හැකිය. උදාහරණයක් ලෙස, class වෙන් කර ඇති keyword එක බැවින් එය හඳුනාගැනීමක් ලෙස භාවිතා කළ නොහැක, නමුත් පහත දැක්වෙන පරිදි class, class එක භාවිතා කළ හැකිය.
1 2 3 4 5 6 |
ublic class @class { public static int MyProperty { get; set; } } @class.MyProperty = 100; |
මතක තබා ගත යුතු කරුණු:
- Keywords යනු වෙන් කර ඇති වචන වන අතර ඒවා name හෝ identifiers ලෙස භාවිතා කළ නොහැක.
- ඔබට එය identifier ලෙස භාවිතා කිරීමට අවශ්ය නම් keyword සමඟ ‘@’ prepix එක යෙදිය හැක.
- C# හි විවිධ වචන වර්ග ඇතුළත් වේ උදා. modifier keywords, access modifiers keywords, statement keywords, method param keywords ආදිය.
- Contextual keywords හඳුනාගැනීමක් ලෙස භාවිතා කළ හැකිය.
ඊලග පාඩමෙන් අපි මුල්ම එක ලියමු !