सबसे पहले, बुनियादी जवाब:
var query = checks.GroupBy<Customer, string>(delegate (Customer c) {
return string.Format("{0} - {1}", c.CustomerId, c.CustomerName);
}).Select(delegate (IGrouping<string, Customer> customerGroups) {
return new { Customer = customerGroups.Key, Payments = customerGroups };
});
तो, आप कैसे बाहर इन बातों को अपने आप को समझ सकता हूँ?
सबसे पहले, here से प्रतिबिंब डाउनलोड करें, और इसे इंस्टॉल करें।
फिर एक छोटा सा कंसोल प्रोग्राम की तरह एक नमूना प्रोग्राम बनाएं, जिसमें वह कोड शामिल है जिसे आप विश्लेषण करना चाहते हैं। यहाँ कोड मैंने लिखा है:
using System;
using System.Collections.Generic;
using System.Linq;
namespace ConsoleApplication11
{
public class Customer
{
public Int32 CustomerId;
public Int32 CustomerName;
}
class Program
{
static void Main(string[] args)
{
var checks = new List<Customer>();
var query = from c in checks
group c by String.Format("{0} - {1}", c.CustomerId, c.CustomerName)
into customerGroups
select new { Customer = customerGroups.Key, Payments = customerGroups };
}
}
}
तो फिर तुम कि निर्माण, और खुले परावर्तक, और यह पूछना सवाल में exe फ़ाइल को खोलने के लिए।
फिर आप प्रश्न में विधि पर नेविगेट करते हैं, जो मेरे मामले में ConsoleApplication11.Program.Main
था।
यहां की चाल प्रतिबिंबक के विकल्प पृष्ठ पर जाना है, और इसे सी # 2.0 सिंटैक्स दिखाने के लिए कहें, जो उपयुक्त स्थिर विधि कॉल के साथ लिंक को प्रतिस्थापित करेगा। ऐसा करने से मेरा पीछा कोड देता है:
private static void Main(string[] args)
{
List<Customer> checks = new List<Customer>();
var query = checks.GroupBy<Customer, string>(delegate (Customer c) {
return string.Format("{0} - {1}", c.CustomerId, c.CustomerName);
}).Select(delegate (IGrouping<string, Customer> customerGroups) {
return new { Customer = customerGroups.Key, Payments = customerGroups };
});
}
अब, बेशक इस कोड lambdas और इसी तरह के साथ एक सा खूबसूरत लिखा जा सकता है, क्या @mquandershowed की तरह है, लेकिन परावर्तक के साथ, कम से कम आप को समझने के लिए सक्षम होना चाहिए विधि कॉल शामिल किया जा रहा है।
अपने भविष्य के संदर्भ के लिए, इस प्रश्न का उत्तर सी # 3.0 विनिर्देशन में दिया गया है, जिसे आप इंटरनेट से डाउनलोड कर सकते हैं। सभी क्वेरी परिवर्तन नियमों को निर्दिष्ट किया गया है। –
ty, नहीं पता था कि परिवर्तन नियम दस्तावेज किए गए थे। –