本文介绍了LINQ in C#的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 29岁程序员,3月因学历无情被辞! 您好, LINQ是否仅适用于var在C#中? 它只能起作用: int [] cc = {1,2,3,4,5,6,7,8,9 }; var b =从p在cc中,其中(p 4)选择p; 但不是这样: int [] cc = {1,2,3,4,5,6,7,8,9}; int [] b =从p in cc其中(p 4)选择p; 欢呼, 罗伯特 解决方案 No.虽然我个人认为没有理由不使用它的大部分 时间。 >它只能起作用: int [] cc = {1,2,3,4,5,6,7,8,9}; var b =来自p in cc其中(p 4)选择p; 但不是这样: int [] cc = {1,2,3,4,5,6,7,8,9}; int [] b =从p in cc其中(p 4)选择p; 嗯,这是真的。表达式from p in cc其中(p 4)select p 返回IEnumerable< T(IEnumerable< intin your case),而不是数组。你不需要使用var - 你可以用它代替: IEnumerable< intb = from p in cc where(p 4)select p; Oliver Sturm - http://www.sturmnet.org/blog 编号虽然我个人认为没有理由不使用它的大部分时间。 >>它只能起作用: int [] cc = {1,2,3,4,5,6,7,8,9}; var b =从p in cc其中(p 4)选择p; 但不是这样: int [] cc = {1,2,3,4 ,5,6,7,8,9}; int [] b =从p in cc,其中(p 4)选择p; 嗯,这是真的。表达式from p in cc其中(p 4)select p 返回IEnumerable< T(IEnumerable< intin your case),而不是数组。你不需要使用var - 你可以用它代替: IEnumerable< intb = from p in cc where(p 4)select p; Oliver Sturm - http://www.sturmnet.org/blog 编号虽然我个人认为没有理由不使用它的大部分时间。 >>它只能起作用: int [] cc = {1,2,3,4,5,6,7,8,9}; var b =从p in cc其中(p 4)选择p; 但不是这样: int [] cc = {1,2,3,4 ,5,6,7,8,9}; int [] b =从p in cc,其中(p 4)选择p; 嗯,这是真的。表达式from p in cc其中(p 4)select p 返回IEnumerable< T(IEnumerable< intin your case),而不是数组。你不需要使用var - 你可以用它代替: IEnumerable< intb = from p in cc where(p 4)select p; Oliver Sturm - http://www.sturmnet.org/blog Hi here,Does LINQ only work with "var" in C#?It only works:int[] cc = { 1, 2, 3, 4, 5, 6, 7, 8, 9 };var b = from p in cc where (p 4) select p;but not this:int[] cc = { 1, 2, 3, 4, 5, 6, 7, 8, 9 };int[] b = from p in cc where (p 4) select p;cheers,Robert 解决方案No. Although I personally wouldn''t see a reason to not use it most of thetime.Well, that''s true. The expression "from p in cc where (p 4) select p"returns IEnumerable<T(IEnumerable<intin your case), not an array. Youdon''t have to use var - you could use this instead:IEnumerable<intb = from p in cc where (p 4) select p;Oliver Sturm-- http://www.sturmnet.org/blogNo. Although I personally wouldn''t see a reason to not use it most of thetime.Well, that''s true. The expression "from p in cc where (p 4) select p"returns IEnumerable<T(IEnumerable<intin your case), not an array. Youdon''t have to use var - you could use this instead: IEnumerable<intb = from p in cc where (p 4) select p; Oliver Sturm-- http://www.sturmnet.org/blogNo. Although I personally wouldn''t see a reason to not use it most of thetime.Well, that''s true. The expression "from p in cc where (p 4) select p"returns IEnumerable<T(IEnumerable<intin your case), not an array. Youdon''t have to use var - you could use this instead: IEnumerable<intb = from p in cc where (p 4) select p; Oliver Sturm-- http://www.sturmnet.org/blog 这篇关于LINQ in C#的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云!
08-19 15:58