Professional Documents
Culture Documents
CS Manual
CS Manual
თბილისი 2017
2
ჯემალ ანთიძე
დაპროგრამება C# ენაზე
თბილისი 2017
3
წინათქმა
ს ა რ ჩ ე ვ ი
1 თავი . ზოგადი ინსტრუქციები . . . .7
1.5 მეთოდები . . . . . . . . . . . . . . . . . . . 38
2.1 კლასები . . . . . . . . . . . . . . . . . . . 52
2.2 მემკვიდრეობითობა . . . . . . . . . . . . . . 56
2.3 პოლიმორფიზმი . . . . . . . . . . . . . . . 61
2.4 თვისებები . . . . . . . . . . . . . . . . . . 64
3.1 მაინდექსირებლები . . . . . . . . . . . . . . 73
3.2 სტრუქტურები . . . . . . . . . . . . . . . . 80
3.3 ინტერფეისები . . . . . . . . . . . . . . . . . 89
9. ველები . . . . . . . . . . . . . . . . . . . . . . . . . . 170
15.ხდომილებები . . . . . . . . . . . . . . . . . . . . . . . 201
C# ლიტერატურა . . . . . . . . . . . 316
7
1 თავი
ზოგადი ინსტრუქციები
შინაარსი :
namespace-ის გამოყენება;
მარტივი C# პროგრამა
// Namespace-ის გამოცხადება
using System;
class Cmisalmeba
// ეკრანზე გამოტანა
Console.WriteLine("ვიწყებთ C# შესწავლას!");
}
8
csc.exe Cmisalmeba.cs
Notepad.exe saxeli.txt
// Namespace-ის გამოცხადება
using System;
class Csaxeli1
// ეკრანზე გამოტანა
Console.WriteLine("გისურვებთ წარმატებას!");
აქ, ჩვენ Main მეთოდში მივუთითეთ არგუმენტი string[] args, რაც ნიშნავს, რომ args
არის string ტიპის მასივი. მისი მნიშვნელობები აიღება ბრძანებათა სტრიქონიდან.
სადაც პირველი სახელი არის პროგრამის ფაილის სახელი და დანარჩენი სახელები
არიან args მასივის ელემენტები. მასივის ელემენტების გადათვლა იწყება ნულიდან.
10
სალამი პეტრე!
გისურვებთ წარმატებას!
using System;
class Csaxeli2
// ცვლადის განსაზღვრა
Console.WriteLine("გისურვებთ წარმატებას!");
}
11
string name=Console.ReadLine() ;
decimal 128 28-29 ათობითი ციფრი 1.0 x 10-28 –დან 7.9 x 1028
\\ დახრილი ხაზი
\0 nul-კოდი
\a ზარი
\b დახრილი ხაზი
\f ფორმის ჩატვირთვა
\t ჰორიზონტალური ტაბულაცია
\v ვერტიკალური ტაბულაცია
კატეგორია პრიორიტეტის
ოპერატორები ასოციატურობა
მიხედვით
მულტიპლიკატორული *, /, % მარცხნივ
ადიტიური +, - მარცხნივ
16
ტოლობის =, != მარცხნივ
ლოგიკური ან | მარცხნივ
პირობითი ან || მარცხნივ
ტერნალური ?: მარჯვნივ
using System;
class Unary
{
17
int unary = 0;
int preIncrement;
int preDecrement;
int postIncrement;
int postDecrement;
int positive;
int negative;
sbyte bitNot;
bool logNot;
preIncrement = ++unary;
preDecrement = --unary;
postDecrement = unary--;
postIncrement = unary++;
positive = -postIncrement;
negative = +postIncrement;
bitNot = 0;
bitNot = (sbyte)(~bitNot);
logNot = false;
logNot = !logNot;
წინასწარ გაზრდა:
წინასწარ შემცირება: 0
შემდეგ შემცირება: 0
შემდეგ გაზრდა: -1
დადებითი: 1
უარყოფითი: -1
ბიტური უარყოფა: -1
19
using System;
class Binary
int x, y, result;
float floatresult;
x = 7;
y = 5;
result = x+y;
result = x-y;
result = x*y;
result = x/y;
floatresult = (float)x/(float)y;
result = x%y;
20
result += x;
x+y: 12
x-y: 2
x*y: 35
x/y: 1
x/y: 1.4
x%y: 2
result+=x: 9
using System;
class Array
myBools[0][0] = true;
myBools[0][1] = false;
myBools[1][0] = true;
myDoubles[0, 0] = 3.147;
myDoubles[0, 1] = 7.157;
myDoubles[1, 1] = 2.117;
myDoubles[1, 0] = 56.00138917;
22
myStrings[0] = "Joe";
myStrings[1] = "Matt";
myStrings[2] = "Robert";
myDoubles[0, 0] = 3.147;
myDoubles[0, 1] = 7.157;
myDoubles[1, 1] = 2.117;
23
myBools[0][0] = true;
myBools[0][1] = false;
myBools[1][0] = true;
მაგალითი 3.1
using System;
class IfSelect
string myInput;
int myInt;
myInput = Console.ReadLine();
myInt = Int32.Parse(myInput);
if (myInt > 0)
if (myInt < 0)
25
// ტოლია თუ არა
if (myInt != 0)
else
// მრავალი ალტერნატივა
{
26
else
myInput = Console.ReadLine();
myInt = Int32.Parse(myInput);
switch(<ცვლადის სახელი>)
case <მნიშვნელობა1> :
<ინსტრუქცია1>
break;
case <მნიშვნელობა2> :
<ინსტრუქცია2>
...
case <მნიშვნელობაn>
<ინსტრუქციაn>
default:
<ინსტრუქცია>
}
28
using System;
class SwitchSelect
string myInput;
int myInt;
begin:
myInput = Console.ReadLine();
myInt = Int32.Parse(myInput);
switch (myInt)
case 1:
break;
case 2:
break;
case 3:
break;
default:
break;
decide:
switch (myInput)
case "continue":
goto begin;
case "quit":
Console.WriteLine("Bye.");
break;
default:
goto decide;
30
განშტოების ინსტრუქციები
განშტოების
აღწერა
ინსტრუქცია
using System;
class WhileLoop
int myInt = 0;
myInt++;
Console.WriteLine();
}
32
ამ პროგრამაში myInt-ს ენიჭება ნული და ედარება 10-ს, რადგან myInt ნაკლებია 10-ზე,
პირობით გამისახულებას ენიჭება true და ეკრანზე გამოიტანება myInt-ის მნიშვნელობა
- ნული. შემდეგ myInt-ის მნიშვნელობა იზრდება ერთით და პროცესი მეორდება, სანამ
myInt არ გახდება 10. ამ დროს პირობითი გამოსახულება მიიღებს მნიშვნელობას false
და ციკლი მთავრდება. ეკრანზე გამოიტანება ცარიელი სტრიქონი და პროგრამა
ამთავრებს მუშაობას.
using System;
class DoLoop
string myChoice;
do
//menu-ს გამოტანა
myChoice = Console.ReadLine();
case "A":
case "a":
break;
case "D":
case "d":
Console.WriteLine("მასამართის წაშლა.");
break;
case "M":
case "m":
Console.WriteLine("მისამართის შესწორება.");
break;
case "V":
case "v":
Console.WriteLine("მისამართების გადათვალიერება.");
34
break;
case "Q":
case "q":
Console.WriteLine("დამთავრება“);
break;
default:
break;
Console.ReadLine();
Console.WriteLine();
// გაგრძელება
using System
class ForLoop
if (i == 10)
break;
if (i % 2 == 0)
continue;
Console.WriteLine();
}
36
using System;
class ForEachLoop
}
37
1.5 მეთოდები
using System;
class OneMethod
{
public static void Main()
{
string myChoice;
Console.WriteLine(“დამთავრება.");
break;
default:
Console.WriteLine("{0} araswori arCevani", myChoice);
break;
}
// პაუზა შედეგის დასათვალიერებლად
Console.WriteLine();
Console.Write(“დააჭირეთ enter-ს მუშაობის გასაგრძელებლად ...");
Console.ReadLine();
Console.WriteLine();
}
string getChoice() {
string myChoice;
// მენიუს გამოტანა
Console.WriteLine(“ჩემი მისამართების წიგნი\n");
Console.WriteLine("A – ახალი მისამართის დამატება");
Console.WriteLine("D – მისამართის წაშლა");
Console.WriteLine("M – მისამართის შესწორება");
Console.WriteLine("V - მისამართების დათვალიერება");
Console.WriteLine("Q - დამთავრება\n");
return myChoice;
}
}
სხვა მხრივ, ეს პროგრამა იგივეა, რაც ადრინდელი პროგრამა. ახლა, განვიხილოთ იგივე
ამოცანის პროგრამა მეთოდის პარამეტრების გამოყენებით.
using System;
class Address
{
public string name;
public string address;
}
class MethodParams
{
public static void Main()
{
string myChoice;
MethodParams mp = new MethodParams();
do
{
// მენიუს ჩვენება და მომხმარებლის არჩევანი.
myChoice = mp.getChoice();
// გაგრძელება დამთავრებამდე
}
// მენიუს ჩვენება და მომხმარებლის არჩევანი
42
string getChoice()
{
string myChoice;
// მენიუს გამოტანა
Console.WriteLine(“ჩემი მისამართების წიგნი");
switch(myChoice)
{
case "A":
case "a":
addr.name = "Joe";
addr.address = "C# Station";
this.addAddress(ref addr);
break;
case "D":
case "d":
addr.name = "Robert";
43
this.deleteAddress(addr.name);
break;
case "M":
case "m":
addr.name = "Matt";
this.modifyAddress(out addr);
// მისამართის დამატება
void addAddress(ref Address addr)
{
Console.WriteLine(“სახელი: {0}, მისამართი: {1} დაემატა.", addr.name, addr.address); }
// მისამართის წაშლა
void deleteAddress(string name)
{
Console.WriteLine(“თქვენ გსურთ {0}-ის მისამართის წაშლა.", name);
}
44
// მისამართის შეცვლა
void modifyAddress(out Address addr)
{
//Console.WriteLine("სახელი: {0}.", addr.name);
//იწვევს შეცდომას!
{
foreach (string name in names)
{
Console.WriteLine(“სახელი: {0}", name);
}
}
}
}
}
}
using System;
namespace csharp_station
{
namespace tutorial
{
class NamespaceCSS
{
public static void Main()
47
{
Console.WriteLine("ეს არის სახელთა არეს მაგალითი.");
}
}
}
}
using System;
namespace csharp_station.tutorial
{
class NamespaceCSS
{
public static void Main()
{
Console.WriteLine("ეს არის ახალი Namespace.");
}
}
;
ინსტრუქცია
namespace csharp_station.tutorial
using System;
namespace csharp_station
{
// ჩადგმული namespace
namespace tutorial
{
48
class myExample1
{
public static void myPrint1()
{
Console.WriteLine("სახელთა არეს წევრის გამოყენების მაგალითი. ");
}
}
}
class NamespaceCalling
{
public static void Main()
{
tutorial.myExample1.myPrint1();
tutorial.myExample2.myPrint2();
}
}
}
// namespace როგორც ზემოთ ჩადგმული namespace
namespace csharp_station.tutorial
{
class myExample2
class UsingDirective
{
public static void Main()
{
// namespace –ის წევრის გამოყენება
myExample.myPrint();
}
}
namespace csharp_station.tutorial
{
class myExample
{
public static void myPrint()
{
Console.WriteLine(“using დირექტივის გამოყენების მაგალითი.");
}
}
}
ამ მაგალითში დირექტივას
using csharp_station.tutorial;
using System;
using csTut = csharp_station.tutorial.myExample;
// მეტსახელი
class AliasDirective
{
public static void Main()
50
{
// namespace –ის გამოძახება
csTut.myPrint();
myPrint();
}
namespace csharp_station.tutorial
{
class myExample
{
public static void myPrint()
{
Console.WriteLine("ეს არის წევრი - csharp_station.tutorial.myExample.");
}}}
ინსტრუქციას
კლასები
სტრუქტურები
ინტერფეისები
51
გადანომვრა
დელეგატები
52
2.1 კლასები. ჩვენ აქამდე მრავალჯერ გამოვიყენეთ კლასები და ვიცით ზოგი რამ
კლასების შესახებ. ახლა, სრულად განვიხილავთ კლასებს. კლასის განსაზღვრა იწყება
გასაღები სიტყვით class, რომელსაც მოსდევს კლასის სახელი და ფიგურულ
ფრჩხილებში მოთავსებული კლასის წევრები. ყოველ კლასს აქვს კონსტრუქტორი,
რომელიც არის მეთოდი და აქვს სახელად კლასის სახელი. მას არა აქვს
დასაბრუნებელი მნიშვნელობა. იგი გამოიძახება ავტომატურად ყოველთვის, როცა
ხდება კლასის ეგზემპლარის შექმნა. დამატებით ჩვენ შეგვიძლია კლასის შიგნით
განვსაზღვროთ მრავალი კონსტრუქტორი და გამოვიყენოთ ნებისმიერი მათგანი
კლასის ეგზემპლარის შექმნის დროს. კონსტრუქტორები განსხვავდებიან
ერთიმეორისაგან პარამეტრებით. კონსტრუქტორის დანიშნულებაა მოახდინოს კლასის
წევრების ინიციალიზაცია კლასის ეგზემპლარის შექმნისას. კლასს აქვს აგრეთვე
დესტრუქტორები. დესტრუქტორი არის მეთოდი, რომლის სახელია კლასის სახელს
წინდართული სიმბოლო ~. იგი გამოიყენება კლასის დახურვის დროს, რომ
გავათავისუფლოთ კლასის მიერ დაკავებული რესურსები. კლასს შეიძლება ჰქონდეს
მრავალი დესტრუქტორი. ისინი ერთიმეორესგან განსხვავდებიან
პარამეტრებით.განვიხილოთმაგალითი:
using System;
// დამხმარე კლასი
class OutputClass
string myString;
// კონსტრუქტორი
myString = inputString;
53
// საობიექტო მეთოდი
Console.WriteLine("{0}", myString);
// დესტრუქტორი
~OutputClass()
class ExampleClass
// OutputClass-ის ეგზემპლიარი
outCl.printString();
}
54
OutputClass.staticPrinter();
55
ჩადგმული კლასები
ველები
მეთოდები
კონსტრუქტორები
დესტრუქტორები
მაინდექსირებლები
თვისებები
ხდომილებები
დელეგატები
56
using System;
public ParentClass()
Console.WriteLine("წინაპარი კონსტრუქტორი.");
Console.WriteLine("წინაპარი კლასი.");
public ChildClass()
{
57
Console.WriteLine("შვილი კონსტრუქტორი.");
child.print();
child.print();
using System;
string parentString;
public Parent()
Console.WriteLine("ძირითადი კონსტრუქტორი.");
parentString = myString;
Console.WriteLine(parentString);
Console.WriteLine("ძირითადი კლასი");
base.print();
Console.WriteLine("წარმოებული კლასი");
child.print();
((Parent)child).print();
child.print()
((Parent)child).print();
using System;
using System;
}
63
using System;
drawObj.Draw();
return 0;
using System;
return m_id;
m_id = id;
}
65
return m_name;
m_name = name;
cust.SetID(1);
cust.SetName("ჯემალ ანთიძე");
Console.WriteLine(
cust.GetID(),
cust.GetName());
Console.ReadKey();
66
am magaliTSi, instruqciiT
m_name-s vaniWebT cariel mniSvnelobas. amisaTvis viyenebT string klasis Empty meTods.
axla, vnaxoT rogor gavakeToT igive Tvisebebis gamoyenebiT:
using System;
public int ID
get
return m_id;
set
m_id = value;
get
return m_name;
set
m_name = value;
cust.ID = 1;
Console.WriteLine(
cust.ID,
68
cust.Name);
Console.ReadKey();
using System;
m_id = id;
m_name = name;
public int ID
69
get
return m_id;
get
return m_name;
Console.WriteLine(
cust.ID,
70
cust.Name);
Console.ReadKey();
aq, ID-s da Name-s aqvT mxolod get. amotom, maT SeuZliaT mxolod
Tvisebis mniSvnelobis wakiTxva. analogiurad, Semdeg magaliTSi SegviZlia
mxolod Tvisebis mniSvnelobis dayeneba:
using System;
public int ID
set
m_id = value;
set
71
m_name = value;
cust.ID = 1;
cust.DisplayCustomerData();
Console.ReadKey();
using System;
cust.ID = 1;
Console.WriteLine(
cust.ID,
cust.Name);
Console.ReadKey();
3 თავი
using System;
class IntIndexer
myData[i] = "ცარიელი";
{
74
get
return myData[pos];
set
myData[pos] = value;
}
75
class OvrIndexer
arrSize = size;
myData[i] = "ცარიელი";
{
76
get
return myData[pos];
set
myData[pos] = value;
get
int count = 0;
if (myData[i] == data)
count++;
return count.ToString();
77
set
if (myData[i] == data)
myData[i] = value;
Console.WriteLine("\nმაინდექსირებლის გამოტანა\n");
get
// dabruneba
set
// dayeneba
79
}
80
struct Rectangle
// marTkuTxedis sigane
get
return m_width;
set
m_width = value;
// მართკუთხედის სიმაღლე
81
get
return m_height;
set
m_height = value;
using System;
class StructExample
{
82
// პროგრამაში შესასვლელი
// სტრუქტურის რეალიზაცია
// სიგრძეა 1 და სიმაღლე 3
rect1.Width = 1;
rect1.Height = 3;
Console.ReadKey();
Width = 1,
Height = 3
};
struct Rectangle
83
// სიგანის მოცემა
get
return m_width;
set
m_width = value;
// ადგილი სიმაღლისათვის
get
{
84
return m_height;
set
m_height = value;
m_width = width;
m_height = height;
}}
using System;
class StructExample
Console.ReadKey();
struct Rectangle
get
return m_width;
set
m_width = value;
get
return m_height;
set
m_height = value;
// parametrebiani konstruqtori
m_width = width;
m_height = height;
// newRect-is dabruneba
return newRect;
using System;
class StructExample
rect1.Width = 1;
rect1.Height = 3;
Console.ReadKey();
Console.ReadKey();
}
89
3.3 ინტერფეისები.
interface IMyInterface
void MethodToImplement();
iImp.MethodToImplement();
Console.WriteLine("MethodToImplement() გამოძახება.");
90
using System;
interface IParentInterface
void ParentInterfaceMethod();
void MethodToImplement();
iImp.MethodToImplement();
iImp.ParentInterfaceMethod();
Console.WriteLine("MethodToImplement() გამოძახება.");
Console.WriteLine("ParentInterfaceMethod() გამოძახება.");
using System;
FirstName = first;
LastName = last;
string n1 = ((Name)name1).FirstName;
string n2 = ((Name)name2).FirstName;
return 1;
return -1;
else
return 0;
class SimpleDelegate
public SimpleDelegate()
{
94
Console.WriteLine("\nდახარისხებამდე: \n");
sd.PrintNames();
sd.Sort(cmp);
sd.PrintNames();
// delegate-ის პარამეტრი
{
95
object temp;
temp = names[i];
names[i] = names[j];
names[j] = (Name)temp;
Console.WriteLine("saxelebi: \n");
Console.WriteLine(name.ToString());
96
...
using System;
using System.Drawing;
using System.Windows.Forms;
// sakuTari delegate
// sakuTari event
public Eventdemo()
clickMe.Parent = this;
(ClientSize.Height - clickMe.Height)/2);
StartEvent();
MessageBox.Show("მე დავიწყე!");
Application.Run(new Eventdemo());
}
99
SecurityException
ArgumentException
PathTooLongException
DirectoryNotFoundException
FileNotFoundException
NotSupportedException
using System;
using System.IO;
class tryCatchDemo
try
File.OpenRead("NonExistentFile");
catch(Exception ex)
Console.WriteLine(ex.ToString());
}
101
catch(FileNotFoundException fnfex)
Console.WriteLine(fnfex.ToString());
catch(Exception ex)
Console.WriteLine(ex.ToString());
using System;
using System.IO;
class FinallyDemo
{
102
try
outStream = File.OpenWrite("DestinationFile.txt");
inStream = File.OpenRead("BogusInputFile.txt");
catch(Exception ex)
Console.WriteLine(ex.ToString());
finally
if (outStream != null)
outStream.Close();
if (inStream != null)
{
103
inStream.Close();
Console.WriteLine("inStream დაიხურა.");
using System;
class BasicAttributeDemo
[Obsolete]
Console.WriteLine("gamoZaxebulia MyFirstdeprecatedMethod().");
[ObsoleteAttribute]
Console.WriteLine("gamoZaxebulia MySecondDeprecatedMethod().");
Console.WriteLine("gamoZaxebulia MyThirdDeprecatedMethod().");
[STAThread]
attrDemo.MyFirstdeprecatedMethod();
attrDemo.MySecondDeprecatedMethod();
attrDemo.MyThirdDeprecatedMethod();
106
[Obsolete]
...
[ObsoleteAttribute]
...
using System;
using System.Runtime.InteropServices;
class AttributeParamsDemo
[DllImport("User32.dll", EntryPoint="MessageBox")]
static extern int MessageDialog(int hWnd, string msg, string caption, int msgType);
[STAThread]
}
107
using System;
[assembly:CLSCompliant(true)]
Console.WriteLine("გამოიძახაNonClsCompliantMethod().");
[STAThread]
uint myUint = 0;
tgtdemo.NonClsCompliantMethod(myUint);
}
4 თავი.
სხვა საშუალებები ეფექტური პროგრამების
შესაქმნელად
4.1 გადანომვრა. ამ პარაგრაფის mizania: SeviswavloT ra aris gadanomrva;
SegeZloT SeqmnaT axali gadanomris tipebi; SeviswavloT rogor
gamoviyenoT isini da gavecnoT System.Enum tipis meTodebs. gadanomrvebi
arian mkacrad tipizirebuli konstantebi. isini arsebiTad arian unikaluri
tipebi, romlebic saSualebas gaZlevT simboluri saxelebis nacvlad
gamoiyenoT mTeli ricxvebi. nebismieri axali aRniSvna gadanomrvis tipsa
da mTel ricxvs Soris moiTxovs cxad gardaqmnas, radgan isini sxvadasxva
tipis arian. simboluri aRniSvnebi arian Sinaarsoblivi, magram arian
mouxerxebeli misaTiTeblad vidre mTeli ricxvebi. magaliTad, Tu gvaqvs
saxelis mqone mniSvnelobebi: orSabaTi, samSabaTi da ase Semdeg kvira da
maT SevusabamebT mTel ricxvebs 0, 1 da ase Semdeg 6, es ricxvebi
SemdgomSi miuTiTeben kviris dReebs. gadanomrvebi arian aRniSnulni enum
an Enum gasaRebi sityvebiT. C#-is enum tipi Base Class Library (BCL)-is Enum
tipis memkvidrea. gamoiyeneT C#-is enum, rom gansazRvroT axali
gadanomrvis tipebi da gamoiyeneT Enum, rom ganaxorcieloT static enum
meTodebi. ganvixiloT magaliTi, Tu rogor gansazRvroT enum tipi da
using System;
// აცხადებს enum-ს
Low,
Medium,
High
// enum-ის გამოყენება
109
class EnumSwitch
switch (myVolume)
case Volume.Low:
Console.WriteLine("ტომი გამორთულია.");
break;
case Volume.Medium:
Console.WriteLine("ტომის ნახევარი.");
break;
case Volume.High:
Console.WriteLine("ტომი ჩაირთო.");
break;
using System;
// acxdebs enum-ს
Low = 1,
Medium,
High
class EnumBaseAndMembers
// Seqmna da inicializacia
switch (myVolume)
case Volume.Low:
Console.WriteLine("ტომი გამოირთო.");
break;
case Volume.Medium:
111
Console.WriteLine("ტომის ნახევარი.");
break;
case Volume.High:
Console.WriteLine("ტომი ჩაირთო.");
break;
Console.ReadLine();
enum bazuri tipi gaCumebiT aris int, magram SeiZleba Seicvalos sxva
bazuri tipiT – byte, rogorc es mocemulia instruqciaSi:
Low = 1
using System;
// enum-is gamocxadeba
Low = 1,
112
Medium,
High
class Enumtricks
// obieqtis Seqmna
enumtricks.GetEnumFromUser();
//iteracia saxeliT
enumtricks.ListEnumMembersByName();
// iteracia miSvnelobiT
enumtricks.ListEnumMembersByValue();
Console.ReadLine();
Console.WriteLine("\n----------------");
113
Console.WriteLine("zomis dayeneba:");
Console.WriteLine("----------------\n");
// cxadi gardaqmna
// cxadi gardaqmna
Console.WriteLine();
switch (myVolume)
case Volume.Low:
Console.WriteLine("ტომი გამოირთო.");
break;
case Volume.Medium:
Console.WriteLine("ტომის ნახევარი.");
break;
case Volume.High:
Console.WriteLine("ტომი ჩაირთო.");
114
break;
Console.WriteLine();
// saxeliT iteracia
Console.WriteLine("\n---------------------------- ");
Console.WriteLine("----------------------------\n");
// miSvnelobiT iteracia
Console.WriteLine("\n----------------------------- ");
Console.WriteLine("-----------------------------\n");
115
}
117
using System;
class Matrix
}
118
// matricebis Sekreba
return newMatrix;
class MatrixTest
// Matrix-is testireba
// matricebis inicializacia
InitMatrix(mat1);
InitMatrix(mat2);
119
// matricebis gamotana
Console.WriteLine("Matrix 1: ");
PrintMatrix(mat1);
Console.WriteLine("Matrix 2: ");
PrintMatrix(mat2);
Console.WriteLine();
PrintMatrix(mat3);
Console.ReadLine();
//matricis inicializacia
mat[x, y] = m_rand.NextDouble();
// matricis gamotana
Console.WriteLine();
Console.Write("[ ");
// gamotanis daformateba
if ((y+1 % 2) < 3)
Console.Write(", ");
Console.WriteLine(" ]");
Console.WriteLine();
igulisxmeba tipisaTvis.
using System;
class BankAccountPublic
return 1000.00m;
class BankAccountPrivate
{
123
using System;
class BankAccountProtected
ApplyPenalties();
CalculateFinalInterest();
DeleteAccountFromDB();
// account-დან გამოყვანა
// account-ის დამატება
}
124
using System;
base.DeleteAccountFromDB();
}
125
using System;
base.DeleteAccountFromDB();
acct.CloseAccount();
ID = id;
Name = name;
public int ID
customers.Add(cust1.ID, cust1);
customers.Add(cust2.ID, cust2);
customers.Add(cust3.ID, cust3);
Console.WriteLine(
custKeyVal.Key,
custKeyVal.Value.Name);
Listing 20-1. Introduction to Using Generic Collections with an Example of the List<T> and
Dictionary<TKey, TValue> Generic Collections
using System;
using System.Collections.Generic;
ID = id;
129
Name = name;
public int ID
class Program
myInts.Add(1);
myInts.Add(2);
130
myInts.Add(3);
customers.Add(cust1.ID, cust1);
customers.Add(cust2.ID, cust2);
customers.Add(cust3.ID, cust3);
Console.WriteLine(
custKeyVal.Key,
custKeyVal.Value.Name);
Console.ReadKey();
}
131
using System.Windows.Forms;
public Form1()
btnHello.Text = "სალამი";
btnHello.Click +=
delegate
MessageBox.Show("სალამი");
};
Controls.Add(btnHello);
using System;
using System.Windows.Forms;
{
132
public Form1()
btnHello.Text = "სალამი";
btnHello.Click +=
delegate
MessageBox.Show("სალამი");
};
btnGoodBye.Text = "მშვიდობით";
btnGoodBye.Left = btnHello.Width + 5;
btnGoodBye.Click +=
MessageBox.Show(message);
};
Controls.Add(btnHello);
Controls.Add(btnGoodBye);
}
133
using System;
class Program
Console.WriteLine("lengthInt =
" + lengthInt);
134
Console.ReadKey();
using System;
class Employee
class Program
joe.Name = "Joe";
135
bob.Name = "Bob";
bob = joe;
Console.WriteLine();
Console.WriteLine();
Console.ReadKey();
using System;
struct Height
class Program
joe.Inches = 71;
bob.Inches = 59;
Console.WriteLine("საწყისი სიმაღლის
მნიშვნელობები:");
bob = joe;
Console.WriteLine();
Console.WriteLine("Values After
Value Assignment:");
joe.Inches = 65;
Console.WriteLine();
Console.WriteLine("Values After
Console.ReadKey();
}
138
int a;
int? b;
if (b == null)
a = 0;
else
a = (int)b;
int? a = null;
an kidev
bull c = a == null;
int b = a ?? 0;
sadac
int? a;
დანართი 1
using System;
using System.IO;
class SavarjiSo
if (!File.Exists(path))
// ფაილის შექმნა
sw.WriteLine("შექმენი,");
sw.WriteLine("შემდეგ წაიკითხე");
string s = "";
Console.WriteLine(s);
}
142
2. მასივის გამოყენება
// arrays.cs
using System;
class DeclareArraysSample
// erTganzomilebiani masivi
// mravalganzomilebiani masivi
}
144
3. ატრიბუტების გამოყენება
// AttributesTutorial.cs
using System;
using System.Reflection;
using System.Collections;
// class.
return "ტესტირებულია";
}
145
// attribute class.
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct)]
this.name = name;
this.version = 0;
get
return name;
}
146
get
return version;
set
version = value;
if (version != 0)
}
147
return value;
[Author("Joe Programmer")]
class Account
orders.Add(orderToAdd);
// კლასზე.
// to this class.
class Order
class MainClass
if (attribute is IsTestedAttribute)
return true;
return false;
{
149
Console.WriteLine(attribute);
DumpAttributes(typeof(Account));
if (IsMemberTested(method))
else
Console.WriteLine();
DumpAttributes(typeof(Order));
150
if (IsMemberTested(method))
else
Console.WriteLine();
}
151
4. სიმბოლოების გამოცნობა
// tokens.cs
using System;
// გამოყენება.
using System.Collections;
elements = source.Split(delimiters);
{
152
private Tokens t;
public TokenEnumerator(Tokens t)
this.t = t;
position++;
return true;
else
{
153
return false;
// IEnumerator-ისთვის:
position = -1;
// IEnumerator-ისთვის:
get
return t.elements[position];
// სიმბოლოების ტესტირება
{
154
Console.WriteLine(item);
}
155
5. სტრუქტურების გამოყენება
// struct1.cs
using System;
struct SimpleStruct
public int X
get
return xval;
set
xval = value;
class TestClass
ss.X = 5;
ss.DisplayX();
}
157
6. თვისებების გამოყენება
// person.cs
using System;
class Person
get
return myName;
set
myName = value;
get
return myAge;
set
myAge = value;
Console.WriteLine("მარტივი თვისებები");
person.Name = "Joe";
person.Age = 99;
person.Age += 1;
}
160
7. მაინდექსირებლების გამოყენება
// indexer.cs
// არგუმენტები: indexer.txt
using System;
using System.IO;
// მასივი
Stream stream;
// ნაკადის დახურვა
stream.Close();
stream = null;
get
stream.Seek(index, SeekOrigin.Begin);
stream.Read(buffer, 0, 1);
return buffer[0];
set
stream.Seek(index, SeekOrigin.Begin);
stream.Write(buffer, 0, 1);
get
162
if (args.Length != 1)
return;
if (!System.IO.File.Exists(args[0]))
return;
163
byte t;
t = file[i];
file[len - i - 1] = t;
file.Close();
}
164
8. დელეგატების გამოყენება
// bookstore.cs
using System;
namespace Bookstore
using System.Collections;
Title = title;
Author = author;
Price = price;
Paperback = paperBack;
}
165
public void AddBook(string title, string author, decimal price, bool paperBack)
if (b.Paperback)
// დელეგატის გამოძახება
processBook(b);
}
166
namespace BookTestClient
using Bookstore;
class PriceTotaller
int countBooks = 0;
countBooks += 1;
priceBooks += book.Price;
}
167
class Test
// აქ იწყება გამოთვლა.
AddBooks(bookDB);
// Test.PrintTitle მეთოდთან.
bookDB.ProcessPaperbackBooks(new ProcessBookDelegate(PrintTitle));
// ობიექტის გამოყენებით
bookDB.ProcessPaperbackBooks(new ProcessBookDelegate(totaller.AddBookToTotal));
totaller.AveragePrice());
// წიგნებით
int availableUnits;
if (unitsInStock == null)
169
availableUnits = 0;
else
availableUnits = (int)unitsInStock;
}
170
9. ველები
using System;
using System.Collections.Generic;
using System.Text;
namespace Yield
class Yield
public static int[] ints = { 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233, 377 };
// რიცხვებს.
if (i % 2 == 0)
yield return i;
}
171
// რიცხვებს.
// დასაბრუნებლად.
if (i % 2 == 1)
yield return i;
Console.WriteLine("ლუწი რიცხვები");
Console.WriteLine(i);
Console.WriteLine("Odd numbers");
Console.WriteLine(i);
}
172
}
173
10. გარდაქმნები
// conversion.cs
using System;
struct RomanNumeral
this.value = value;
return roman.value;
}
174
class Test
RomanNumeral numeral;
numeral = 10;
Console.WriteLine((int)numeral);
Console.WriteLine(numeral);
// მთელიდან short-ში.
short s = (short)numeral;
Console.WriteLine(s);
}
175
// structconversion.cs
using System;
struct RomanNumeral
this.value = value;
return roman.value;
struct BinaryNumeral
this.value = value;
return(binary.value);
177
class Test
RomanNumeral roman;
roman = 10;
BinaryNumeral binary;
binary = (BinaryNumeral)(int)roman;
roman = binary;
Console.WriteLine((int)binary);
Console.WriteLine(binary);
}
178
// dbbool.cs
using System;
// სთვის.
int value;
DBBool(int value)
this.value = value;
// true ან false-ს.
// ოპერანდი არის
// ოპერანდებიდან არის
// არის
// შემთხვევებში აბრუნებს
// dbFalse:
: "dbNull";
try
catch
return false;
return value;
switch (value)
case -1:
return "DBBool.False";
case 0:
return "DBBool.Null";
case 1:
return "DBBool.True";
default:
class Test
DBBool a, b;
a = DBBool.dbTrue;
b = DBBool.dbNull;
// ბულის მნიშვნელობა.
if (b)
else
// complex.cs
this.real = real;
this.imaginary = imaginary;
185
// სასურველ ფორმატში.
// გამოყენებით
}
187
using System;
class NullableOperator
return null;
return null;
// ?? ოპერატორის მაგალითი.
int? x = null;
int y = x ?? -1;
string s = GetStringValue();
// გამოვიტანოთ "Unspecified".
using System;
class NullableBoxing
int? a;
object oa;
// hasValue = false).
a = null;
// მთელი "int?".
if (a == null)
Console.WriteLine(" a == null");
if (oa == null)
Console.WriteLine(" oa == null");
int? b = 10;
object ob = b;
try
{
190
catch (Exception e)
using System;
class NullableBasics
if (num.HasValue == true)
else
Console.WriteLine("num = null");
}
191
try
catch (InvalidOperationException e)
Console.WriteLine(e.Message);
DisplayValue(1);
DisplayValue(null);
}
192
13. ბიბლიოთეკები
// FunctionClient.cs
// შედგენა /reference:DigitCounter.dll;Factorial.dll-ით
// არგუმენტები: 3 5 10
using System;
using Functions;
class FunctionClient
Console.WriteLine("Function Client");
if ( args.Length == 0 )
return;
Console.WriteLine(
args[i],
// DigitCount class-ში:
DigitCount.NumberOfDigits(args[i]));
Console.WriteLine(
num,
Factorial.Calc(num) );
// Factorial.cs
using System;
namespace Functions
{
194
// მთელისათვის.
// DigitCounter.cs
// /target:library-ით კომპილირება
using System;
namespace Functions
// გადაცემულ სტრიქონში
{
195
int count = 0;
if ( Char.IsDigit(theString[i]) )
count++;
return count;
}
196
// explicit1.cs
interface IDimensions
float Length();
float Width();
float lengthInches;
float widthInches;
lengthInches = length;
widthInches = width;
float IDimensions.Length()
return lengthInches;
}
197
float IDimensions.Width()
return widthInches;
// "myBox"ინტერფეისის გამოცხადება:
// "myDimensions"ინტერფეისის გამოცხადება:
}
198
// explicit2.cs
interface IEnglishDimensions
float Length();
float Width();
interface IMetricDimensions
float Length();
float Width();
// IEnglishDimensions და IMetricDimensions:
float lengthInches;
float widthInches;
lengthInches = length;
widthInches = width;
float IEnglishDimensions.Length()
return lengthInches;
float IEnglishDimensions.Width()
return widthInches;
float IMetricDimensions.Length()
float IMetricDimensions.Width()
}
200
// "myBox"ობიექტის გამოცხადება:
15. ხდომილებები
// events1.cs
using System;
namespace MyCollections
using System.Collections;
if (Changed != null)
Changed(this, e);
202
int i = base.Add(value);
OnChanged(EventArgs.Empty);
return i;
base.Clear();
OnChanged(EventArgs.Empty);
set
base[index] = value;
OnChanged(EventArgs.Empty);
}
203
namespace TestEvents
using MyCollections;
class EventListener
List = list;
List = null;
class Test
list.Add("item 1");
list.Clear();
listener.Detach();
// events2.cs
205
using System;
namespace MyCollections
using System.Collections;
if (Changed != null)
Changed(this,e);
int i = base.Add(value);
OnChanged(EventArgs.Empty);
206
return i;
base.Clear();
OnChanged(EventArgs.Empty);
set
base[index] = value;
OnChanged(EventArgs.Empty);
namespace TestEvents
using MyCollections;
class EventListener
{
207
List = list;
List = null;
class Test
list.Add("item 1");
list.Clear();
listener.Detach();
}
209
// cmdline1.cs
// არგუმენტები: A B C
using System;
args.Length);
// cmdline2.cs
210
using System;
args.Length);
foreach(string s in args)
Console.WriteLine(s);
}
211
17. კოლექციები
// tokens.cs
using System;
using System.Collections;
elements = source.Split(delimiters);
// IEnumerable ინტერფეისი:
// მიერ
}
212
private Tokens t;
public TokenEnumerator(Tokens t)
this.t = t;
position++;
return true;
else
return false;
}
213
position = -1;
get
return t.elements[position];
{
214
Console.WriteLine(item);
// tokens2.cs
using System;
using System.Collections;
elements = source.Split(delimiters);
IEnumerator IEnumerable.GetEnumerator()
{
215
private Tokens t;
public TokenEnumerator(Tokens t)
this.t = t;
position++;
return true;
else
return false;
}
216
position = -1;
get
return t.elements[position];
object IEnumerator.Current
get
return t.elements[position];
Console.WriteLine(item);
}
218
// tokens.cs
using System;
using System.Collections;
elements = source.Split(delimiters);
// მიერ:
private Tokens t;
public TokenEnumerator(Tokens t)
this.t = t;
position++;
return true;
else
return false;
}
220
position = -1;
get
return t.elements[position];
Console.WriteLine(item);
// tokens2.cs
using System;
using System.Collections;
elements = source.Split(delimiters);
IEnumerator IEnumerable.GetEnumerator()
222
// IEnumerable ვერსია
private Tokens t;
public TokenEnumerator(Tokens t)
this.t = t;
position++;
return true;
else
{
223
return false;
position = -1;
get{
return t.elements[position];
object IEnumerator.Current
get
return t.elements[position];
}
224
Console.WriteLine(item);
xml დოკუმენტი
// XMLsample.cs
// /doc:XMLsample.xml-ით კომპილაცია
using System;
/// <summary>
/// <remarks>
/// <summary>
/// <summary>
public SomeClass()
/// <summary>
/// <value>
get
if ( myName == null )
return myName;
/// <summary>
/// You can use the cref attribute on any tag to reference a type or member
/// and the compiler will check that the reference exists. </seealso>
/// <summary>
/// <returns>
/// Notice the use of the cref attribute to reference a specific method </seealso>
return 0;
227
/// <summary>
/// </summary>
return 0;
}
228
19. ვერსიები
// versioning.cs
// მოსალოდნელია CS0114.
return "MyBase-Meth1";
return "MyBase-Meth2";
return "MyBase-Meth3";
{
229
// გამოყენებით:
return "MyDerived-Meth1";
// გამოყენებით:
return "MyDerived-Meth2";
return "MyDerived-Meth3";
System.Console.WriteLine(mB.Meth1());
System.Console.WriteLine(mB.Meth2());
System.Console.WriteLine(mB.Meth3());
}
231
20. დაუცველი
// readfile.cs
using System;
using System.Runtime.InteropServices;
using System.Text;
class FileReader
IntPtr handle;
[DllImport("kernel32", SetLastError=true)]
string FileName,
uint DesiredAccess,
uint ShareMode,
uint SecurityAttributes,
uint CreationDisposition,
uint FlagsAndAttributes,
232
int hTemplateFile);
[DllImport("kernel32", SetLastError=true)]
IntPtr hFile,
void* pBuffer,
int NumberOfBytesToRead,
int* pNumberOfBytesRead,
int Overlapped);
[DllImport("kernel32", SetLastError=true)]
IntPtr hObject);
handle = CreateFile(
FileName,
GENERIC_READ,
0,
0,
OPEN_EXISTING,
0,
0);
233
if (handle != IntPtr.Zero)
return true;
else
return false;
int n = 0;
return 0;
return n;
return CloseHandle(handle);
}
234
class Test
if (args.Length != 1)
return 1;
if (! System.IO.File.Exists(args[0]))
return 1;
if (fr.Open(args[0]))
{
235
int bytesRead;
do
Console.Write("{0}", content);
fr.Close();
return 0;
else
return 1;
}
236
// printversion.cs
// კომპილაცია /unsafe-ით:
using System;
using System.Reflection;
using System.Runtime.InteropServices;
[DllImport("version.dll")]
[DllImport("version.dll")]
[DllImport("version.dll")]
[DllImport("version.dll")]
public class C
try
int handle = 0;
int size =
Win32Imports.GetFileVersionInfoSize("printversion.exe",
out handle);
{
238
return 1;
uint len = 0;
return 1;
string versionInfo;
return 1;
}
239
catch (Exception e)
return 0;
// fastcopy.cs
// კომპილაცია /unsafe-ით:
using System;
class Test
byte* ps = pSrc;
byte* pd;
*((int*)pd) = *((int*)ps);
pd += 4;
ps += 4;
}
241
*pd = *ps;
pd++;
ps++;
a[i] = (byte)i;
Copy(a, 0, b, 0, 100);
Console.WriteLine("\n");
}
242
21. ძაფები
using System;
using System.Threading;
using System.Collections;
using System.Collections.Generic;
// Producer classes.
public SyncEvents()
// fail to terminate.
_eventArray[0] = _newItemEvent;
_eventArray[1] = _exitThreadEvent;
_queue = q;
_syncEvents = e;
int count = 0;
{
245
lock (((ICollection)_queue).SyncRoot)
_queue.Enqueue(r.Next(0, 100));
_syncEvents.NewItemEvent.Set();
count++;
// The Consumer class uses its own worker thread to consume items
{
246
_queue = q;
_syncEvents = e;
int count = 0;
while (WaitHandle.WaitAny(_syncEvents.EventArray) != 1)
lock (((ICollection)_queue).SyncRoot)
count++;
lock (((ICollection)q).SyncRoot)
foreach (int i in q)
Console.WriteLine();
// actual threads.
producerThread.Start();
consumerThread.Start();
Thread.Sleep(2500);
249
ShowQueueContents(queue);
syncEvents.ExitThreadEvent.Set();
// Use Join to block primary thread, first until the producer thread
producerThread.Join();
consumerThread.Join();
using System;
using System.Threading;
{
250
while (!_shouldStop)
_shouldStop = true;
// Create the thread object. This does not start the thread.
workerThread.Start();
while (!workerThread.IsAlive);
Thread.Sleep(1);
workerObject.RequestStop();
workerThread.Join();
using System;
using System.Threading;
_n = n;
_doneEvent = doneEvent;
_fibOfN = Calculate(_n);
_doneEvent.Set();
if (n <= 1)
253
return n;
else
ManualResetEvent _doneEvent;
fibArray[i] = f;
ThreadPool.QueueUserWorkItem(f.ThreadPoolCallback, i);
WaitHandle.WaitAll(doneEvents);
Console.WriteLine("Calculations complete.");
// შედეგების გამოტანა...
Fibonacci f = fibArray[i];
}
255
22. უსაფრთხოება
// ImperativeSecurity.cs
using System;
using System.Security;
using System.Security.Permissions;
using System.Runtime.InteropServices;
class NativeMethods
[DllImport("msvcrt.dll")]
[DllImport("msvcrt.dll")]
class MainClass
// ნებართვა:
SecurityPermission perm =
new SecurityPermission(SecurityPermissionFlag.UnmanagedCode);
// აკრძალეთ UnmanagedCode.
// უმართავ კოდზე.
// calls Assert for unmanaged code, you still cannot call native
// overwritten.
perm.Deny();
try
NativeMethods.puts("Hello World!");
NativeMethods._flushall();
catch (SecurityException)
{
257
SecurityPermission perm =
new SecurityPermission(SecurityPermissionFlag.UnmanagedCode);
// გამოიწვევს SecurityExcept
perm.Assert();
try
NativeMethods.puts("Hello World!");
NativeMethods._flushall();
catch (SecurityException)
258
SecurityPermission(SecurityPermissionFlag.UnmanagedCode);
perm.Assert();
CallUnmanagedCodeWithoutPermission();
perm.Deny();
CallUnmanagedCodeWithPermission();
}
259
// DeclarativeSecurity.cs
using System;
using System.Security;
using System.Security.Permissions;
using System.Runtime.InteropServices;
class NativeMethods
[DllImport("msvcrt.dll")]
[DllImport("msvcrt.dll")]
class MainClass
[SecurityPermission(SecurityAction.Deny, Flags =
SecurityPermissionFlag.UnmanagedCode)]
260
try
NativeMethods.puts("Hello World!");
NativeMethods._flushall();
catch (SecurityException)
[SecurityPermission(SecurityAction.Assert, Flags =
SecurityPermissionFlag.UnmanagedCode)]
try
NativeMethods.puts("Hello World!");
NativeMethods._flushall();
catch (SecurityException)
SecurityPermission(SecurityPermissionFlag.UnmanagedCode);
perm.Assert();
CallUnmanagedCodeWithoutPermission();
perm.Deny();
CallUnmanagedCodeWithPermission();
262
// SuppressSecurity.cs
using System;
using System.Security;
using System.Security.Permissions;
using System.Runtime.InteropServices;
class NativeMethods
[SuppressUnmanagedCodeSecurityAttribute()]
[DllImport("msvcrt.dll")]
[SuppressUnmanagedCodeSecurityAttribute()]
[DllImport("msvcrt.dll")]
class MainClass
{
263
[SecurityPermission(SecurityAction.Deny, Flags =
SecurityPermissionFlag.UnmanagedCode)]
try
UIPermission uiPermission =
new UIPermission(PermissionState.Unrestricted);
uiPermission.Demand();
NativeMethods.puts("Hello World!");
NativeMethods._flushall();
catch (SecurityException)
[SecurityPermission(SecurityAction.Assert, Flags =
SecurityPermissionFlag.UnmanagedCode)]
264
try
NativeMethods.puts("Hello World!");
NativeMethods._flushall();
catch (SecurityException)
SecurityPermission(SecurityPermissionFlag.UnmanagedCode);
perm.Assert();
CallUnmanagedCodeWithoutPermission();
perm.Deny();
265
CallUnmanagedCodeWithPermission();
}
266
23. pinvoke
// Marshal.cs
using System;
using System.Runtime.InteropServices;
class PlatformInvokeTest
[DllImport("msvcrt.dll")]
[MarshalAs(UnmanagedType.LPStr)]
string m);
[DllImport("msvcrt.dll")]
puts("Hello World!");
_flushall();
// pinvoke.cs
267
// კომპილაცია /addmodule:logfont.netmodule-ით
using System;
using System.Runtime.InteropServices;
class PlatformInvokeTest
[DllImport("gdi32.dll", CharSet=CharSet.Auto)]
[In, MarshalAs(UnmanagedType.LPStruct)]
LOGFONT lplf
);
[DllImport("gdi32.dll")]
IntPtr handle
);
lf.lfHeight = 9;
lf.lfFaceName = "Arial";
if (IntPtr.Zero == handle)
268
else
if (IntPtr.Size == 4)
Console.WriteLine("{0:X}", handle.ToInt32());
else
Console.WriteLine("{0:X}", handle.ToInt64());
if (!DeleteObject(handle))
}
269
// logfont.cs
// კომპილაცია /target:module-ით
using System;
using System.Runtime.InteropServices;
[StructLayout(LayoutKind.Sequential)]
[MarshalAs(UnmanagedType.ByValTStr, SizeConst=LF_FACESIZE)]
// PInvokeTest.cs
using System;
using System.Runtime.InteropServices;
class PlatformInvokeTest
[DllImport("msvcrt.dll")]
[DllImport("msvcrt.dll")]
puts("Test");
_flushall();
}
271
using System;
using System.Collections.Generic;
using System.Text;
namespace PartialClassesExample
class PartialClassesMain
if (args.Length != 1)
return;
using System;
using System.Collections.Generic;
using System.Text;
namespace PartialClassesExample
int count = 0;
if (IsAlphabetic(ch))
count++;
273
return count;
int count = 0;
if (IsNumeric(ch))
count++;
return count;
using System;
using System.Collections.Generic;
using System.Text;
namespace PartialClassesExample
{
274
return true;
return true;
return false;
return true;
return false;
}
275
25. oledb
// OleDbSample.cs
// csc oledbsample.cs
using System;
using System.Data;
using System.Data.OleDb;
using System.Xml.Serialization;
// command line-ში:
#if USINGPROJECTSYSTEM
#else
#endif
try
catch(Exception ex)
return;
try
myAccessConn.Open();
myDataAdapter.Fill(myDataSet,"Categories");
277
return;
finally
myAccessConn.Close();
// მასივში:
{0}", dt.TableName);
int i = 0;
}}
279
// indexedproperty.cs
using System;
// მსგავსად:
internal WordCollection(Document d)
document = d;
int count = 0;
start = length = 0;
if (inWord >= 0)
if (!isLetter)
if (count++ == wordCount)
start = inWord;
length = i - inWord;
return true;
inWord = -1;
else
281
if (isLetter)
inWord = i;
return false;
get
out length))
else
set
out length))
if (length == value.Length)
Array.Copy(value.ToCharArray(), 0,
else
char[] newText =
new char[document.TextArray.Length +
value.Length - length];
Array.Copy(document.TextArray, 0, newText,
0, start);
Array.Copy(value.ToCharArray(), 0, newText,
start, value.Length);
document.TextArray.Length - start
- length);
document.TextArray = newText;
}
283
else
get
++count;
return count;
// სიმბოლოების მასივი
284
internal CharacterCollection(Document d)
document = d;
get
return document.TextArray[index];
set
document.TextArray[index] = value;
{
285
get
return document.TextArray.Length;
// როგორც "ინდექსირებულითვისებები":
TextArray = initialText.ToCharArray();
get
class Test
"peter piper picked a peck of pickled peppers. How many pickled peppers did peter piper
pick?"
);
if (d.Words[i] == "peter")
d.Words[i] = "penelope";
if (d.Characters[i] == 'p')
d.Characters[i] = 'P';
287
Console.WriteLine(d.Text);
}
288
27. generics
using System;
using System.Collections;
using System.Collections.Generic;
using System.Text;
namespace Generics_CSharp
private T data;
public Node(T t)
289
next = null;
data = t;
public T Data
public MyList()
head = null;
}
290
n.Next = head;
head = n;
current = current.Next;
}
291
IEnumerator IEnumerable.GetEnumerator()
return GetEnumerator();
return;
bool swapped;
do
swapped = false;
if (current.Data.CompareTo(current.next.Data) > 0)
current.next = current.next.next;
tmp.next = current;
if (previous == null)
head = tmp;
else
previous.next = tmp;
previous = tmp;
swapped = true;
else
previous = current;
current = current.next;
}
293
} while (swapped);
string name;
int age;
name = s;
age = i;
}
294
class Generics
string[] names = new string[] { "Franscoise", "Bill", "Li", "Sandra", "Gunnar", "Alok",
"Hiroyuki", "Maria", "Alessandro", "Raul" };
int[] ages = new int[] { 45, 19, 28, 23, 18, 9, 108, 72, 30, 35 };
//სიის პოპულაცია.
295
Console.WriteLine("Unsorted List:");
Console.WriteLine(p.ToString());
//სიის დახარისხება.
list.BubbleSort();
Console.WriteLine(p.ToString());
Console.WriteLine("Done");
}
296
28. cominterop2
// CSharpServer.cs
using System;
using System.Runtime.InteropServices;
namespace CSharpServer
[Guid("DBE0E8C4-1C61-41f3-B6A4-4E2F353D3D05")]
[Guid("C6659361-1625-4746-931C-36014B146679")]
return 33;
297
}
298
29. cominterop1
// interop2.cs
using System;
using System.Runtime.InteropServices;
namespace QuartzTypeLib
// IDispatch ინტერფეისიდან:
[Guid("56A868B1-0AD4-11CE-B03A-0020AF0BA770"),
InterfaceType(ComInterfaceType.InterfaceIsDual)]
interface IMediaControl
// აქ:
void Run();
void Pause();
void Stop();
void RenderFile(
void AddSourceFilter(
[Out, MarshalAs(UnmanagedType.Interface)]
[return: MarshalAs(UnmanagedType.Interface)]
object FilterCollection();
[return: MarshalAs(UnmanagedType.Interface)]
object RegFilterCollection();
void StopWhenReady();
[ComImport, Guid("E436EBB3-524F-11CE-9F53-0020AF0BA770")]
class FilgraphManager
// კონსტრუქტორს
}
300
class MainClass
/**********************************************************
Returns: void
*************************************************************/
if (args.Length != 1)
DisplayUsage();
return;
}
301
if (args[0] == "/?")
DisplayUsage();
return;
if (!System.IO.File.Exists(filename))
DisplayUsage();
return;
// (იძახებს CoCreateInstance(E436EBB3-524F-11CE-9F53-0020AF0BA770,
// &graphManager).):
try
QuartzTypeLib.FilgraphManager graphManager =
new QuartzTypeLib.FilgraphManager();
QuartzTypeLib.IMediaControl mc =
302
(QuartzTypeLib.IMediaControl)graphManager;
mc.RenderFile(filename);
// ფაილის ჩვენება.
mc.Run();
catch(Exception ex)
// დასრულების ლოდინი.
Console.ReadLine();
// interop1.cs
using System;
class MainClass
/************************************************************
the AVI.The main thread blocks on a ReadLine until the user presses
Enter.
Returns: void
**************************************************************/
DisplayUsage();
return;
if (args[0] == "/?")
DisplayUsage();
return;
if (!System.IO.File.Exists(filename))
DisplayUsage();
return;
// (იძახებს CoCreateInstance(E436EBB3-524F-11CE-9F53-0020AF0BA770,
305
try
QuartzTypeLib.FilgraphManager graphManager =
new QuartzTypeLib.FilgraphManager();
QuartzTypeLib.IMediaControl mc =
(QuartzTypeLib.IMediaControl)graphManager;
mc.RenderFile(filename);
// აჩვენე ფაილი.
mc.Run();
catch(Exception ex)
// დასრულების ლოდინი.
Console.ReadLine();
306
// Display-ის გამოყენება:
}
307
using System;
using System.Collections.Generic;
using System.Text;
namespace AnonymousDelegate_Sample
class Employee
class Program
decimal multiplier = 2;
// ეს დელეგატი ანონიმიურია.
staff[0].sales = 100;
staff[0].calculation_algorithm = standard_bonus;
staff[1].sales = 200;
staff[1].calculation_algorithm = standard_bonus;
staff[2].sales = 300;
staff[2].calculation_algorithm = standard_bonus;
staff[3].sales = 100;
staff[3].calculation_algorithm = enhanced_bonus;
staff[4].sales = 250;
staff[4].calculation_algorithm = enhanced_bonus;
PerformBonusCalculation(person);
DisplayPersonDetails(person);
}
310
person.bonus = person.calculation_algorithm(person.sales);
Console.WriteLine(person.name);
Console.WriteLine(person.bonus);
Console.WriteLine("---------------");
}
311
დანართი 2
anchor ღუზა
batton ღილაკი
broser ბროუზერი
bynary ორობითი
class კლასი
coding კოდირება
debuger გამმართველი
debugging გამართვა
default გაჩუმება
environment გარემო
errors შეცდომები
form ფორმა
field ველი
file ფაილი
format ფორმატი
frame ჩარჩო
Gateway ჭიშკარი
host მასპინძელი
handler დამამუშავებელი
313
hash ხეში
key გასაღები
list სია
load ჩატვირთვა
menu მენიუ
object ობიექტი
parameter პარამეტრი
patch გზა
pipe არხი
pointer მიმთითებელი
query შეკითხვა
reference მითითება
script სკრიპტი
shortcats შემოკლებები
site საიტი
space ხარვეზისნიშანი
table ცხრილი
tag ჭდე
user მომხმარებელი
variable ცვლადი
C# ლიტერატურა