defination的一些问题... c# [英] some problem with defination...c#

查看:114
本文介绍了defination的一些问题... c#的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要一个人用c#向我解释一些代码,它们是什么意思...我正在使用它,但说实话我不理解
这是代码:

Hi, I need some one to explain me some code in c#, what does they mean... I am using that but to tell te truth I don understand that
here is the code :

GroupBy(name => name).Select(group => string.Format("{0} [{1}]",group.Key , group.Count()))

string.Format("{0} [{1}]  --- ???  I have the result  e.x  Europe[4] 


所以可以解释任何一个,这是什么意思"{0} ande [{1}]"谢谢

gorup.key ---?
group.Count ----?


so can explain any one, what does it mean "{0} ande [{1}] " thank you

gorup.key ---?
group.Count----?

推荐答案

{0}和{1}是string.Format格式字符串的参数,由第一个和第二个替换构造新字符串时,格式字符串后面的参数:在这种情况下,分别由"group.Key"和"group.Count()"组成.字符"["和]"只是直接复制到输出字符串中的文字字符,正如您在打印中看到的那样.有4个欧洲"项目.

"group"是由GroupBy Linq扩展方法返回的可枚举列表中每个项目的名称.
认为是:
{0} and {1} are parameters to the string.Format format string, which are replaced by the first and second parameters following the format string when constructing a new string: in this case, by "group.Key" and "group.Count()" respectively. The ''['' and '']'' characters are just literal characters copied directly to the output string - as you can see in your print. There are 4 "Europe" items.

"group" is the name given to each item in the enumerable list returned by the GroupBy Linq extension method.
Think of it as:
foreach (var group in GroupBy(name => name))
   {
   Select(string.Format("{0} [{1}]",group.Key , group.Count()));
   }

不是那样做的,无论如何也不会编译,但是它使您了解发生了什么.

It isn''t done like that, and that wouldn''t compile anyway, but it gives you an idea what is going on.


您能指定什么吗?无论是DataTable,Dictionary还是其他东西,GroupBy

至于字符串格式,它将把字符串作为参数提供给您.那些括号就是应该在什么位置出现什么文本的位置,因此第0个位置组.键值将出现在{1}对象数处将会出现
Can You Specify what is GroupBy whether it is DataTable or Dictionary or some thing else

As for the string format it will concatenate the string what ever you give as a parameter.Those brackets are just the position in what popsition what text should come so 0''th position group.key value will come and at {1} object count will come


要了解LINQ,我将看以下文章:
To understand LINQ I would look at the following article: How does it work in C#? - Part 3 (C# Linq in detail)[^]


这篇关于defination的一些问题... c#的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆