PDA

View Full Version : مجموعه ها در #C



SalarSoft
دوشنبه 03 اسفند 1383, 08:14 صبح
برای تعریف مجموعه ها در دلفی ما این کار رو می کنیم:


type Sample=(s1,s2,s3,s4);
و برای تعریف نوع جدیدی از اعضای این مجموعه از دستور زیر استفاده می کنیم:


exam=set of sample;
که می توانیم اعمال اشتراک ، اجتماع و ... غیره را روی متغیر تعریف شده از نوع exam انجام دهیم.

می دانم که برای تعریف مجموعه در c# ار enum استفاده می کنند. ولی برای تعریف بقیه کارهای چگونه عمل میکنند؟ :(

Peyman_Ranjbar
دوشنبه 03 اسفند 1383, 23:28 عصر
تعریف enum



public enum numbers{one,two,three};


:flower:

SalarSoft
سه شنبه 04 اسفند 1383, 15:00 عصر
اینو می دونم!
ولی سوال من اینه که نوع جدیدی از نوع مثلا exam باشه که بتوان به متغیر تعریف شده از آن اعضای مجموعه exam را اظافه و حذف کرد:

مثلا یه همچین چیزی:

pubic exam myColl={s1,s2};

myColl=myColl+{s1}; :flower:

SalarSoft
پنج شنبه 06 اسفند 1383, 16:44 عصر
مثل اینکه سوالم رو بد مطرح کردم!

یک بار دیگه: معادل این کد دلفی در #C چیست؟


type Sample=(s1,s2,s3,s4);
exam=set of sample;

procedure Example;
var
ex:exam;
begin
ex:=[s1,s2,s3];
ex:=ex-[s2];
end; :flower:

M.GhanaatPisheh
جمعه 07 اسفند 1383, 11:42 صبح
تنها چیزی که به درخواست شما نزدیکتر بود همین بود.
اگر توضیحی لازم بود بفرمایید.


using System;

public class EnumTest {
enum Days { Saturday, Sunday, Monday, Tuesday, Wednesday, Thursday, Friday };
enum BoilingPoints { Celcius = 100, Fahrenheit = 212 };
[FlagsAttribute]
enum Colors { Red = 1, Green = 2, Blue = 4, Yellow = 8 };

public static void Main() {

Type weekdays = typeof(Days);
Type boiling = typeof(BoilingPoints);

Console.WriteLine("The days of the week, and their corresponding values in the Days Enum are:");

foreach ( string s in Enum.GetNames(weekdays) )
Console.WriteLine( "{0,-11}= {1}", s, Enum.Format( weekdays, Enum.Parse(weekdays, s), "d"));

Console.WriteLine();
Console.WriteLine("Enums can also be created which have values that represent some meaningful amount.");
Console.WriteLine("The BoilingPoints Enum defines the following items, and corresponding values:");

foreach ( string s in Enum.GetNames(boiling) )
Console.WriteLine( "{0,-11}= {1}", s, Enum.Format(boiling, Enum.Parse(boiling, s), "d"));

Colors myColors = Colors.Red | Colors.Blue | Colors.Yellow;
Console.WriteLine();
Console.WriteLine("myColors holds a combination of colors. Namely: {0}", myColors);
}
}

SalarSoft
شنبه 08 اسفند 1383, 16:03 عصر
ممنون.
تقریبا همینه!

هیچی دستور زبان دلفی نمیشه!

M.GhanaatPisheh
شنبه 08 اسفند 1383, 17:09 عصر
هیچی دستور زبان دلفی نمیشه!
:mad:
یه کلاس بنویسید که این کار رو بکنه.
کار راحتیه.