Linq101-Restriction

  1 using System;
  2 using System.Linq;
  3
  4 namespace Linq101
  5 {
  6     class Restriction
  7     {
  8         /// <summary>
  9         /// This sample uses where to find all elements of an array less than 5.
 10         /// </summary>
 11         public void Simple1()
 12         {
 13             int[] numbers = { 5, 4, 1, 3, 9, 8, 6, 7, 2, 0 };
 14
 15             var query = from n in numbers
 16                         where n < 5
 17                         select n;
 18
 19             Console.WriteLine("Numbers < 5 :");
 20             foreach (var number in query)
 21             {
 22                 Console.WriteLine(number);
 23             }
 24         }
 25
 26         /// <summary>
 27         /// This sample uses where to find all products that are out of stock.
 28         /// </summary>
 29         public void Simple2()
 30         {
 31             var productList = Data.GetProductList();
 32
 33             var query = from product in productList
 34                         where product.UnitsInStock == 0
 35                         select product;
 36
 37             Console.WriteLine("Sold out products:");
 38             foreach (var product in query)
 39             {
 40                 Console.WriteLine("{0} is sold out!", product.ProductName);
 41             }
 42         }
 43
 44         /// <summary>
 45         /// This sample uses where to find all products that are in stock and cost more than 3.00 per unit.
 46         /// </summary>
 47         public void Simple3()
 48         {
 49             var productList = Data.GetProductList();
 50
 51             var query = from product in productList
 52                         where product.UnitsInStock > 0 && product.UnitPrice > 3.00M
 53                         select product;
 54
 55             Console.WriteLine("In-stock products that cost more than 3.00:");
 56             foreach (var product in query)
 57             {
 58                 Console.WriteLine("{0} is in stock and cost more than 3.00", product.ProductName);
 59             }
 60         }
 61
 62         /// <summary>
 63         /// This sample uses where to find all customers in Washington and then uses the resulting sequence to drill down into their orders.
 64         /// </summary>
 65         public void Simple4()
 66         {
 67             var customerList = Data.GetCustomerList();
 68
 69             var query = from customer in customerList
 70                         where customer.Region == "WA"
 71                         select customer;
 72
 73             Console.WriteLine("Cutomers from Washington and their orders:");
 74             foreach (var customer in query)
 75             {
 76                 Console.WriteLine("Customer {0}:{1}", customer.CustomerID, customer.CompanyName);
 77                 foreach (var order in customer.Orders)
 78                 {
 79                     Console.WriteLine("    Order {0}:{1}", order.OrderID, order.OrderDate);
 80                 }
 81             }
 82         }
 83
 84         /// <summary>
 85         /// This sample demonstrates an indexed Where clause that returns digits whose name is shorter than their value.
 86         /// </summary>
 87         public void Simple5()
 88         {
 89             string[] digits = { "zero", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine" };
 90
 91             var query = digits.Where((digit, index) => digit.Length < index);
 92
 93             Console.WriteLine("Short digits:");
 94             foreach (var digit in query)
 95             {
 96                 Console.WriteLine("The word {0} is shorter than its value.", digit);
 97             }
 98         }
 99
100         /// <summary>
101         /// 有一个整数数组,我们找出这个数字是否跟他在这个数组的位置一样
102         /// </summary>
103         public void Simple5plus1()
104         {
105             int[] numbers = { 5, 4, 1, 3, 9, 8, 6, 7, 2, 0 };
106
107             // 摘要:
108             //     基于谓词筛选值序列。 将在谓词函数的逻辑中使用每个元素的索引。
109             //
110             // 参数:
111             //   source:
112             //     要筛选的 System.Collections.Generic.IEnumerable<T>。
113             //
114             //   predicate:
115             //     用于测试每个源元素是否满足条件的函数;该函数的第二个参数表示源元素的索引。
116             //
117             // 类型参数:
118             //   TSource:
119             //     source 中的元素的类型。
120             //
121             // 返回结果:
122             //     一个 System.Collections.Generic.IEnumerable<T>,包含输入序列中满足条件的元素。
123             //
124             // 异常:
125             //   System.ArgumentNullException:
126             //     source 或 predicate 为 null。
127             //public static IEnumerable<TSource> Where<TSource>(this IEnumerable<TSource> source, Func<TSource, int, bool> predicate);
128             var numbersInPlace = numbers.Where((n, index) => n == index);
129
130             Console.WriteLine("数字跟其位置一样的有:");
131             foreach (var number in numbersInPlace)
132             {
133                 Console.WriteLine(number);
134             }
135         }
136     }
137 }
时间: 2024-11-02 18:55:48

Linq101-Restriction的相关文章

not accessible due to restriction on required library

The type AWTUtilities is not accessible due to restriction on required library D:\Program Files\jdk1.6.0_24\jre\lib\rt.jar”, Access restriction: The type WindowsLookAndFeel is not accessible due to restriction on required library 解决的方法:在project build

NHibernate Criteria中 Restriction与Expression的差别

http://stackoverflow.com/questions/5483393/nhibernate-criteria-restriction-vs-expression 据说是Restriction在NH2的时候发布,到目前为止Restriction是最佳方法  

TNS-12540: TNS:internal limit restriction exceeded

监听日志listener.log里面出现了 TNS-12518: TNS:listener could not hand off client connection与TNS-12540: TNS:internal limit restriction exceeded错误,如下所示,用户连接不上ORACLE数据库: 27-JAN-2015 10:10:19 * (CONNECT_DATA=(SERVICE_NAME=scm2)(CID=(PROGRAM=c:\windows\system32\in

thinkPHP5配置nginx环境无法打开(require(): open_basedir restriction in effect. File(/mnt/hgfs/root/tp5/thinkphp/start.php) is not within the allowed path(s)

今天想把玩一下tp5,结果怎么都无法访问,每次都是报500错误,我把错误提示都打开看到下面的错误 require(): open_basedir restriction in effect. File(/mnt/hgfs/root/tp5/thinkphp/start.php) is not within the allowed path(s): (/mnt/hgfs/root/tp5/public/:/tmp/:/proc/) 1,我是php7 ,php.ini里面的open_basedir

Access restriction: The type TaskTopicResolver is not accessible due to restrict--编译Hadoop时有个SecurityUtils有错误,处理方法

Access restriction: The type TaskTopicResolver is not accessible due to restrict 做NC的时候从别人那拷了个NC_DEMO结果我这报错他那没报错 import nc.bs.wfengine.engine.ext.TaskTopicResolver; 报错信息:Access restriction: The type TaskTopicResolver is not accessible due to restrict

java 错误:Access restriction: The type Resource is not accessible due to restriction on required library

Eclipse 默认把这些受访问限制的API设成了ERROR.只要把Windows-Preferences-Java-Complicer- Errors/Warnings里面的Deprecated and restricted API中的Forbidden references(access rules)选为Warning就可以编译通过. java 错误:Access restriction: The type Resource is not accessible due to restrict

Access restriction: The type &#39;BASE64Encoder&#39; is not API

问题的原因好像是这个方法不是安全的,所以不推荐使用,我是在做毕设时要用到的所以就直接用了(毕设要求没有那么严格的要求) Access restriction: The type 'BASE64Encoder' is not API (restriction on required library '/home/rocky/develop/jdk1.8.0_65/jre/lib/rt.jar') Access restriction: The type 'BASE64Encoder' is not

2015/5/7 Access restriction: The type &#39;BASE64Encoder&#39; is not API

Access restriction: The type 'BASE64Encoder' is not API (restriction on required library 'D:\Java\jdk1.6.0_43\jre\lib\rt.jar') 引入import sun.misc.BASE64Encoder; 是红叉,怎么解决? 右键项目,点属性(Properties): java bulid path-->Libraries-->jre System Library: Access

使用myeclipse开发java,解决java中继承JFrame类出现The type JFrame is not accessible due to restriction的问题

在java中创建窗体,导入了java中的JFrame类,之后会出现错误: Access restriction: The type QName is not accessible due to restriction on required library D:\myeclipse professer2014 可以解决的办法为: Project—>Properties—>选中Java Build Path—>选择Libraries,出现下面界面: 选中窗口中原有的JRE库,点击Remov

Access restriction: The method createJPEGEncoder(OutputStream) from the type JPEGCodec is not access

准备使用Java进行图片压缩的时候,使用 import com.sun.image.codec.jpeg.*; 结果出现错误: Access restriction: The method createJPEGEncoder(OutputStream) from the type JPEGCodec is not accessible due to restriction on required library 上网查了一下,发现是IDE的设置问题,它默认把这些受访问限制的API设成了ERROR