شبیه سازی ساده نوع داده برگشتی در سی شارپ
با سلام،
ما در این فرصت عید چند تا سول پرسیدیم و مزاحم دوستان شدیم . :n40:
من نمیفهمم این نوع داده برگشتی چجور هست؟ درسته میشه با var از دست این موضوع خلاص شد اما دو دلیل داشت. یکی بفهمیم پشت پرده چه خبر هست و این قضیه جور پیاده شده و دیگری اگر بخواهیم این داده رو برای متد یا کلاس دیگر بفرستیم با var امکان نداشت و نوع داده مشخص رو نیاز داره.
کد:
IEnumerable<IGrouping<string,Customer>>
یا مثلا
کد:
IEnumerable<IEnumerable<>>
کد:
staticvoidMain(string[] args)
{
IEnumerable<IGrouping<string,Customer>> groupQuery =
from c in customers
group c by c.State;
IEnumerable<IGrouping<bool,Customer>> groupPriceQuery =
from c in customers
group c by c.Price>=1000;
foreach(IGrouping<bool,Customer> priceGroup in groupPriceQuery)
{
Console.WriteLine("{0}", priceGroup.Key);
foreach(Customer c in priceGroup)
{
Console.WriteLine(" {0} {1}: {2}", c.First, c.Last, c.Price);
}
}
Console.ReadKey();
}
یعنی میشه این قطعه کد ساده رو که نوشتم لطفا اصلاحش کنید تا درک کنیم نوع داده برگشتی به شکل بالا چگونه پیاده سازی شده...ممنون
کد:
usingSystem;
namespaceConsoleApp9
{
interface IA<TSource>
{
voidAMethod(int a);
}
interface IB : IA<int>
{
voidBMethod(string str);
}
classProgram: IA<int>
{
staticvoidMain(string[] args)
{
IA<int> a =newProgram();
}
publicvoidAMethod(int a)
{
Console.WriteLine("IA Interface");
}
}
}