视频演示:http://u.115.com/file/f2ce0eeb6

输出序列可能不包含源序列的任何元素或元素属性。输出可能是通过将源元素用作输入参数计算出的值的序列。在执行下面这个简单查询时,此查询会输出一个字符串序列,该序列值表示根据 double 类型的元素的源序列进行的计算。
说明
如果查询将转换为某个其他域,则不支持在查询表达式中调用方法。例如,不能在 LINQ to SQL 中调用一般C#方法,因为 SQL Server 没有该方法的上下文。但是,可以将存储过程映射到方法,然后调用方法。

// Data source.   
double[] Radii = { 1, 2, 3, 4, 5, 6, 7, 8, 9 };   
  
// Results.   
IEnumerable<string> Results =   
    from Rad in Radii   
    select String.Format("Area = {0}", (Rad * Rad) * 3.14);   
  
// Results execution.    
foreach (string Result in Results)   
    Console.WriteLine(Result);   
  
// Keep the console open in debug mode.   
Console.WriteLine("Press any key to exit.");   
Console.ReadKey()  
// Data source.
double[] Radii = { 1, 2, 3, 4, 5, 6, 7, 8, 9 };

// Results.
IEnumerable<string> Results =
    from Rad in Radii
    select String.Format("Area = {0}", (Rad * Rad) * 3.14);

// Results execution. 
foreach (string Result in Results)
    Console.WriteLine(Result);

// Keep the console open in debug mode.
Console.WriteLine("Press any key to exit.");
Console.ReadKey() 


输出如下:

Area = 3.14   
Area = 12.56   
Area = 28.26   
Area = 50.24   
Area = 78.5   
Area = 113.04   
Area = 153.86   
Area = 200.96   
Area = 254.34 

相关文章:

  • 2021-08-02
  • 2021-07-14
  • 2021-06-17
  • 2021-09-19
  • 2021-08-19
  • 2021-10-20
  • 2021-08-17
  • 2021-07-15
猜你喜欢
  • 2021-09-25
  • 2021-05-31
  • 2021-10-01
  • 2021-09-09
  • 2021-06-21
  • 2021-05-28
  • 2021-06-08
相关资源
相似解决方案