English 中文(简体)
如何使用LINQ订购数据
原标题:How to order data using LINQ

我试图将以下数据按发生顺序排列,我使用缩微软件的代码,有两点错误,我想知道人们将如何解决这一问题? 感谢。

 List<Alpha> letters = new List<Alpha>
        {
            new Alpha {letter = A , occur = new List<int>{A}},
            new Alpha {letter = B , occur = new List<int>{B}},
            new Alpha {letter = C , occur = new List<int>{C}},
            new Alpha {letter = D , occur = new List<int>{D}},
            new Alpha {letter = E , occur = new List<int>{E}},
            new Alpha {letter = F , occur = new List<int>{F}},
            new Alpha {letter = G , occur = new List<int>{G}},
            new Alpha {letter = H , occur = new List<int>{H}},
            new Alpha {letter = I , occur = new List<int>{I}},
            new Alpha {letter = J , occur = new List<int>{J}},
            new Alpha {letter = K , occur = new List<int>{K}},
            new Alpha {letter = L , occur = new List<int>{L}},
            new Alpha {letter = M , occur = new List<int>{M}},
            new Alpha {letter = N , occur = new List<int>{N}},
            new Alpha {letter = O , occur = new List<int>{O}},
            new Alpha {letter = P , occur = new List<int>{P}},
            new Alpha {letter = Q , occur = new List<int>{Q}},
            new Alpha {letter = R , occur = new List<int>{R}},
            new Alpha {letter = S , occur = new List<int>{S}},
            new Alpha {letter = T , occur = new List<int>{T}},
            new Alpha {letter = U , occur = new List<int>{U}},
            new Alpha {letter = V , occur = new List<int>{V}},
            new Alpha {letter = W , occur = new List<int>{W}},
            new Alpha {letter = X , occur = new List<int>{X}},
            new Alpha {letter = Y , occur = new List<int>{Y}},
            new Alpha {letter = Z , occur = new List<int>{Z}},

        };

i 没有任何打字,实际上它们是变体名称,因此,这些变体有编号,因此,“INT”思想本来会充满激动,令人不安,问题是,你会如何命令数字发生。 che

问题回答

页: 1 在固定打字之后,你实际上已订购收集物:

List<Alpha> letters = new List<Alpha>
        {
            new Alpha {letter = A , occur = new List<int>{ A }},
            new Alpha {letter = B , occur = new List<int>{ B }},
            new Alpha {letter = C , occur = new List<int>{ C }},
            new Alpha {letter = D , occur = new List<int>{ D }},
            new Alpha {letter = E , occur = new List<int>{ E }},
            new Alpha {letter = F , occur = new List<int>{ F }},
            new Alpha {letter = G , occur = new List<int>{ G }},
            new Alpha {letter = H , occur = new List<int>{ H }},
            new Alpha {letter = I , occur = new List<int>{ I }},
            new Alpha {letter = J , occur = new List<int>{ J }},
            new Alpha {letter = K , occur = new List<int>{ K }},
            new Alpha {letter = L , occur = new List<int>{ L }},
            new Alpha {letter = M , occur = new List<int>{ M }},
            new Alpha {letter = N , occur = new List<int>{ N }},
            new Alpha {letter = O , occur = new List<int>{ O }},
            new Alpha {letter = P , occur = new List<int>{ P }},
            new Alpha {letter = Q , occur = new List<int>{ Q }},
            new Alpha {letter = R , occur = new List<int>{ R }},
            new Alpha {letter = S , occur = new List<int>{ S }},
            new Alpha {letter = T , occur = new List<int>{ T }},
            new Alpha {letter = U , occur = new List<int>{ U }},
            new Alpha {letter = V , occur = new List<int>{ V }},
            new Alpha {letter = W , occur = new List<int>{ W }},
            new Alpha {letter = X , occur = new List<int>{ X }},
            new Alpha {letter = Y , occur = new List<int>{ Y }},
            new Alpha {letter = Z , occur = new List<int>{ Z }},

        };

如果这些信件已经分类:

var sortedLetters = 
        from p in letters 
        orderby p.letter 
        select p;

在对你的打字之后,这应当为你工作:

var sortedLetters  =  (from c in letters select c).OrderBy(d=>d.letter)




相关问题
Anyone feel like passing it forward?

I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...

NSArray s, Primitive types and Boxing Oh My!

I m pretty new to the Objective-C world and I have a long history with .net/C# so naturally I m inclined to use my C# wits. Now here s the question: I feel really inclined to create some type of ...

C# Marshal / Pinvoke CBitmap?

I cannot figure out how to marshal a C++ CBitmap to a C# Bitmap or Image class. My import looks like this: [DllImport(@"test.dll", CharSet = CharSet.Unicode)] public static extern IntPtr ...

How to Use Ghostscript DLL to convert PDF to PDF/A

How to user GhostScript DLL to convert PDF to PDF/A. I know I kind of have to call the exported function of gsdll32.dll whose name is gsapi_init_with_args, but how do i pass the right arguments? BTW, ...

Linqy no matchy

Maybe it s something I m doing wrong. I m just learning Linq because I m bored. And so far so good. I made a little program and it basically just outputs all matches (foreach) into a label control. ...

热门标签