C# : LINQ
Top 37 C# Example Pages...

["swtry. .*BBB`BBBBCST~~}T~~Y696F5A5A5R(BBC/CBES}T~~}T~~","OrderBy"," specifies how a collection should be ordered. It is an extension method. With the System.Linq namespace in the C# language, we can invoke OrderBy on any collection that implements IEnumerable.","Example."," First we declare a string array. Next we invoke OrderBy and pass a lambda expression that matches the signature of Func as the argument. On the right side of the lambda, after =>, we reverse each string to get the sort key. ","String Array ","array","String Literal ","string-literal","Func ","func","We do this"," by converting the string to an array with ToCharArray. Then we use the Reverse extension method. Next we convert that to a character array with ToArray. And finally we convert to a new string with the string constructor. ","ToCharArray ","tochararray","Reverse ","reverse","ToArray ","toarray","String Constructor ","string-constructor","Info: ","The result (of type IOrderedEnumerable) consists of the four strings sorted by their characters considered in reverse order.","ins","class","adsbygoogle","data-ad-client","ca-pub-4712093147740724","data-ad-slot","6227126509","data-ad-format","auto","ins","class","adsbygoogle","data-ad-client","ca-pub-4712093147740724","data-ad-slot","6227126509","data-ad-format","auto","C# program that uses OrderBy extension method","\n\nusing System;\nusing System.Linq;\n\nclass Program\n{\n static void Main()\n {","\n // Input array.\n ","string[] array = { \"the\", \"glass\", \"bead\", \"game\" };","\n\n // Order alphabetically by reversed strings.\n ","var result = array.","OrderBy","(a => new string(a.ToCharArray().Reverse().ToArray()));","\n\n // Display results.\n ","foreach (var item in result)\n {\n Console.WriteLine(item);\n }\n }\n}\n\n","Output","\n\nbea","d","\nt","h","e","\nga","m","e","\nglas","s","Discussion."," The OrderBy method is used by the C# compiler whenever you use the orderby contextual keyword in a query expression. Query expressions are translated into method chains that include functions such as OrderBy and OrderByDescending. ","orderby ","orderby","OrderByDescending ","orderbydescending","Tip: ","In some program contexts query expressions are easier to read. This is particularly true if multiple transforms in LINQ are required.","Summary."," We saw an example of the OrderBy extension method. By using OrderBy with other syntax forms such as lambda expressions and the foreach-loop, we gain another way to sort collections without directly calling the default Sort methods. ","Typically: ","The performance of extension methods such as OrderBy is inferior to that of the built-in sort methods such as Array.Sort.","Foreach ","foreach","Array.Sort ","array-sort","ins","class","adsbygoogle","data-ad-client","ca-pub-4712093147740724","data-ad-slot","3679700504","data-ad-format","link","ins","class","adsbygoogle","data-ad-client","ca-pub-4712093147740724","data-ad-slot","6227126509","data-ad-format","auto","url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAALwAAABGCAAAAABTK6EIAAACe0lEQVR4XtXa4XHCMAyG4W7iQTSPxvEu2kWTaIL0aO69a48kwjnsIv0PPMjoIzj+8kdtY8U1Cyrcump7lGo3j9+Or/aoQUB2TaPs5gsgN20U1W0VXu7hobfDUluDb3Yf79LOSmMJXm/jrVGq9lNdBb34Cnzzm3hHbvEL4AyBxFz8/v79Hj5kp/sTwIQlnYrf9AGIW/i+J8vRxa5M01S88SbD+NjtV6uik/GbkJZDeBovcTkPNhVP68fxge6kdG/9RDwIHccbjb9sfczEs/w+jO/k1GXrbTLeUYzhhc98uTR9Lp60HMKTNZH9hOlcPCM7hoeWRmnMxJPJOoTnS5ELfCoeiI3hO9dkEzsXT1qO4fVD8KTlON4vBbYCT1oO4duLeJ2NJy1L4lnhIXxO8iV40nKAF5+DZ2Rfx/ur+DYdT1rWxDOyFfFoekU8rZcoiSctS+JJy5p40rIknrSsiSctK+IB9VK3B09pOXBjFh+DJy0L3RI/j2xNPGlZ52/gwci+6w94X4mHFEW2Po5X+h2bTuB9GZ60fMN2H4JYh6f1OT4w/etG62laJrr2CVvcJ2kJ/u7EMtIr8aQl+KSxmu5wr8STluAznGcfbiWekQWfJWFPUn4tnrTM8Ubrrx4WrsbT+rRjiu/iGfJaPGmZ4gGqH9mFxq/Fk5bgszBsYgfHn5hm8HZc/na8NyrBh+5I/YNwE05QgT8tezt+0xyPHoVo56TTH9h6vOV49P2MJb4txlOS4ynThLUcby/h4R92XwL89tkVvn/XOdEqNLUA/mThoiKeuFLwJVvv4Eu2viae+7KaeM4tlsRzYhR8zZmtiOf5HPh6rRcGtqI+fgDfESNWSoHcSIUAAAAASUVORK5CYII=)","url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E0ulp0OOdAOqLLr8DDipGyFeV2EkjG5YiSVf1+2iS5zST3V5aQPhNSC6kW0SaZd1iyy6WfiXury08eEFuv88thW6qlvWdSeL8O90GbcqKVF0KbbVi7q128FkG8cIvqAb/kKgPYouhbaSY925lDqSLeIOVv8aFRffo+zaK9PhiNYmCG8RcrCVGv3YQLGuypveS6n1n3etpcuCxWmB0wt7rc1ssyKwMK1tmNMb+IkAZ8yC6L42Vop2FhXTUQloeAByXjdus+VAN0Dpki6KtC/rxgU0bBHaXtRFj/Y73UyHuuSJbC/rokbToMkF3SgLLdQIbI91m6qek8ggDItvrBu3QUKPPC6lmQ51TSXrm0DBOqm91s6ZThK0uUiDSudG+Q+cSRLJ2s8yWgAAAABJRU5ErkJggg==)"]

["url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAG4AAACCAgMAAADasxWRAAAADFBMVEX/6Nn///+VlZX29va5ksB5AAAASElEQVR4AWPACZj/f0DmjkqOSjKtQgcLyJccZiEE9SOmP8mXHEaBMBoIo4EwGggryJccvvVKKAogTnJUclRyVHLklgmjkqOSAALWyrsxEHLDAAAAAElFTkSuQmCC)","url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAALwAAAByCAAAAADMwOSzAAACe0lEQVR4Xu3csY7kMAgG4Lz/86Wkp6ZAokDy6RTfodVsTDSaxPy7/uux9a0LZpkEb20YNzNVEWYmItr/hYiYWcS8Tcw2cKv8DTPtoxCzqFfC+wGXgCchYlGvgDfp9MBd/xNsIj7otL8XHwC8x14Sq04/Yine4tRvwEvP6ypqPXp+dgneY+nbaZPwHscOh7eww+HDjoL/uJ1m4D3scPjYFw8fawDxUWjw8LErFP7TB7/z0/jYFA8fB4+Il1iQh47UwF//fvrfLPV/t0WEj+52Ev5yjWc96y/MNNrdR/EX6yRZuxb3Z/Ge10lu1/MsPm9auZXFS09iL4n3DE+tLD5vQrQsPi+U1ArjJcELAv7Og/eeAT4+cor3r2lbVPk7Sk30ODeEt3R/QcZ7YXxWbK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