CSHARPWINDOWSFORM Telegram 205
بسم الله الرحمن الرحيم


C# Enum


المعداد هو "فئة" خاصة تمثل مجموعة من الثوابت (متغيرات غير قابلة للتغيير / للقراءة فقط).

لإنشاء معداد ، استخدم كلمة enum وافصل عناصر التعداد بفاصلة:


Example

enum Level
{
Low,
Medium,
High
}
يمكنك الوصول إلى عناصر المعداد باستخدام النقطة (dot)

Level myVar = Level.Medium;
Console.WriteLine(myVar);



يمكنك أيضًا اضافة تعداد داخل الفصل:

Example

class Program
{
enum Level
{
Low,
Medium,
High
}
static void Main(string[] args)
{
Level myVar = Level.Medium;
Console.WriteLine(myVar);
}
}
قيم المعداد

بشكل افتراضي ، يحتوي العنصر الأول من المعداد على القيمة 0. والثاني له القيمة 1 ، وهكذا.

للحصول على القيمة الصحيحة من عنصر ، يجب عليك تحويل العنصر بشكل صريح إلى int:


Example
enum Months
{
January, // 0
February, // 1
March, // 2
April, // 3
May, // 4
June, // 5
July // 6
}

static void Main(string[] args)
{
int myNum = (int) Months.April;
Console.WriteLine(myNum);
}


يمكنك أيضًا تعيين قيم المعداد الخاصة بك ، وستقوم العناصر التالية بتحديث الرقم وفقًا لذلك

Example
enum Months
{
January, // 0
February, // 1
March=6, // 6
April, // 7
May, // 8
June, // 9
July // 10
}

static void Main(string[] args)
{
int myNum = (int) Months.April;
Console.WriteLine(myNum);
}
The output will be:
7


Enum in a Switch Statement

غالبًا ما يتم استخدام المعدادات في عبارات switch للتحقق من القيم المقابلة
Example
enum Level
{
Low,
Medium,
High
}

static void Main(string[] args)
{
Level myVar = Level.Medium;
switch(myVar)
{
case Level.Low:
Console.WriteLine("Low level");
break;
case Level.Medium:
Console.WriteLine("Medium level");
break;
case Level.High:
Console.WriteLine("High level");
break;
}
}


انتهى ............

https://www.tgoop.com/CsharpWindowsForm



tgoop.com/CsharpWindowsForm/205
Create:
Last Update:

بسم الله الرحمن الرحيم


C# Enum


المعداد هو "فئة" خاصة تمثل مجموعة من الثوابت (متغيرات غير قابلة للتغيير / للقراءة فقط).

لإنشاء معداد ، استخدم كلمة enum وافصل عناصر التعداد بفاصلة:


Example

enum Level
{
Low,
Medium,
High
}
يمكنك الوصول إلى عناصر المعداد باستخدام النقطة (dot)

Level myVar = Level.Medium;
Console.WriteLine(myVar);



يمكنك أيضًا اضافة تعداد داخل الفصل:

Example

class Program
{
enum Level
{
Low,
Medium,
High
}
static void Main(string[] args)
{
Level myVar = Level.Medium;
Console.WriteLine(myVar);
}
}
قيم المعداد

بشكل افتراضي ، يحتوي العنصر الأول من المعداد على القيمة 0. والثاني له القيمة 1 ، وهكذا.

للحصول على القيمة الصحيحة من عنصر ، يجب عليك تحويل العنصر بشكل صريح إلى int:


Example
enum Months
{
January, // 0
February, // 1
March, // 2
April, // 3
May, // 4
June, // 5
July // 6
}

static void Main(string[] args)
{
int myNum = (int) Months.April;
Console.WriteLine(myNum);
}


يمكنك أيضًا تعيين قيم المعداد الخاصة بك ، وستقوم العناصر التالية بتحديث الرقم وفقًا لذلك

Example
enum Months
{
January, // 0
February, // 1
March=6, // 6
April, // 7
May, // 8
June, // 9
July // 10
}

static void Main(string[] args)
{
int myNum = (int) Months.April;
Console.WriteLine(myNum);
}
The output will be:
7


Enum in a Switch Statement

غالبًا ما يتم استخدام المعدادات في عبارات switch للتحقق من القيم المقابلة
Example
enum Level
{
Low,
Medium,
High
}

static void Main(string[] args)
{
Level myVar = Level.Medium;
switch(myVar)
{
case Level.Low:
Console.WriteLine("Low level");
break;
case Level.Medium:
Console.WriteLine("Medium level");
break;
case Level.High:
Console.WriteLine("High level");
break;
}
}


انتهى ............

https://www.tgoop.com/CsharpWindowsForm

BY برمجة تطبيقات الويندوز C# Programming




Share with your friend now:
tgoop.com/CsharpWindowsForm/205

View MORE
Open in Telegram


Telegram News

Date: |

Joined by Telegram's representative in Brazil, Alan Campos, Perekopsky noted the platform was unable to cater to some of the TSE requests due to the company's operational setup. But Perekopsky added that these requests could be studied for future implementation. As the broader market downturn continues, yelling online has become the crypto trader’s latest coping mechanism after the rise of Goblintown Ethereum NFTs at the end of May and beginning of June, where holders made incoherent groaning sounds and role-played as urine-loving goblin creatures in late-night Twitter Spaces. Other crimes that the SUCK Channel incited under Ng’s watch included using corrosive chemicals to make explosives and causing grievous bodily harm with intent. The court also found Ng responsible for calling on people to assist protesters who clashed violently with police at several universities in November 2019. To upload a logo, click the Menu icon and select “Manage Channel.” In a new window, hit the Camera icon. On June 7, Perekopsky met with Brazilian President Jair Bolsonaro, an avid user of the platform. According to the firm's VP, the main subject of the meeting was "freedom of expression."
from us


Telegram برمجة تطبيقات الويندوز C# Programming
FROM American