• 博客园logo
  • 会员
  • 众包
  • 新闻
  • 博问
  • 闪存
  • 赞助商
  • HarmonyOS
  • Chat2DB
    • 搜索
      所有博客
    • 搜索
      当前博客
  • 写随笔 我的博客 短消息 简洁模式
    用户头像
    我的博客 我的园子 账号设置 会员中心 简洁模式 ... 退出登录
    注册 登录
光脚丫思考的专栏
十年窗下无人问,一举成名天下知!
博客园    首页    新随笔    联系   管理    订阅  订阅

光脚丫学LINQ(011):对源元素执行操作

视频演示: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 
posted @ 2010-10-29 16:03  光脚丫思考  阅读(231)  评论(0)    收藏  举报
刷新页面返回顶部
博客园  ©  2004-2025
浙公网安备 33010602011771号 浙ICP备2021040463号-3