Professional IronPython



Download 20,35 Mb.
Pdf ko'rish
bet344/453
Sana01.07.2022
Hajmi20,35 Mb.
#723045
1   ...   340   341   342   343   344   345   346   347   ...   453
328

CHAPTER 16
ExtEnding ironPython Using C#
you decide to use an extension with IronPython, you need to consider when it’s appropriate to work 
through the extra code and cumbersome features of static languages and when IronPython is truly 
the better choice.
Let’s look at a quick example. Say you want to create an array of names in a function and pass them 
back to a caller. Here’s the C# code to perform the task.
public String[] GetNames()
{
String[] Result = new String[4];
Result[0] = “John”;
Result[1] = “Amy”;
Result[2] = “Jose”;
Result[3] = “Carla”;
return Result;
}
public void ShowNames()
{
String[] TheNames = GetNames();
foreach (String Name in TheNames)
{
Console.WriteLine(Name);
}
}
The code in 
GetNames()
creates an array of 
String
, fills it with names, and returns those names to the 
caller, 
ShowNames()
. At this point, 
ShowNames()
uses a 
foreach
loop to display each name individually. 
Now take a look at the same functionality written in IronPython.
def GetNames():
return “John”, “Amy”, “Jose”, “Carla”
def ShowNames():
for Name in GetNames():
print Name
The code performs the same task in both cases, but as you can see, the IronPython code is significantly 
shorter. In addition, the IronPython code is actually easier to read.
Considering Scoping Issues
One of the most important differences between IronPython and static languages such as C# is that 
IronPython doesn’t have the concept of scope within classes. Everything in an IronPython class is 
public, so you always have access to every element. Of course, this presents a dilemma for languages 
that do support scope. When creating an IronPython extension, your static language scope declara-
tions will change as follows:
➤➤
Public
members remain public.


Protected
members become public.
548592c16.indd 328
2/24/10 12:49:21 PM
www.finebook.ir



Download 20,35 Mb.

Do'stlaringiz bilan baham:
1   ...   340   341   342   343   344   345   346   347   ...   453




Ma'lumotlar bazasi mualliflik huquqi bilan himoyalangan ©hozir.org 2024
ma'muriyatiga murojaat qiling

kiriting | ro'yxatdan o'tish
    Bosh sahifa
юртда тантана
Боғда битган
Бугун юртда
Эшитганлар жилманглар
Эшитмадим деманглар
битган бодомлар
Yangiariq tumani
qitish marakazi
Raqamli texnologiyalar
ilishida muhokamadan
tasdiqqa tavsiya
tavsiya etilgan
iqtisodiyot kafedrasi
steiermarkischen landesregierung
asarlaringizni yuboring
o'zingizning asarlaringizni
Iltimos faqat
faqat o'zingizning
steierm rkischen
landesregierung fachabteilung
rkischen landesregierung
hamshira loyihasi
loyihasi mavsum
faolyatining oqibatlari
asosiy adabiyotlar
fakulteti ahborot
ahborot havfsizligi
havfsizligi kafedrasi
fanidan bo’yicha
fakulteti iqtisodiyot
boshqaruv fakulteti
chiqarishda boshqaruv
ishlab chiqarishda
iqtisodiyot fakultet
multiservis tarmoqlari
fanidan asosiy
Uzbek fanidan
mavzulari potok
asosidagi multiservis
'aliyyil a'ziym
billahil 'aliyyil
illaa billahil
quvvata illaa
falah' deganida
Kompyuter savodxonligi
bo’yicha mustaqil
'alal falah'
Hayya 'alal
'alas soloh
Hayya 'alas
mavsum boyicha


yuklab olish