diff --git a/LinqStudy.Test/LinqToObject/ConvertTest.cs b/LinqStudy.Test/LinqToObject/ConvertTest.cs deleted file mode 100644 index 1ad9e06..0000000 --- a/LinqStudy.Test/LinqToObject/ConvertTest.cs +++ /dev/null @@ -1,22 +0,0 @@ -using System; -using System.Collections; -using System.Collections.Generic; -using System.Linq; -using System.Text; - -using Xunit; - -namespace LinqStudy.Test.LinqToObject -{ - /// - /// 转换运算符 - /// - public class ConvertTest - { - [Fact] - public void Test() - { - var cc= Enumerable.Empty(); - } - } -} diff --git a/LinqStudy.Test/LinqToObject/TypeConvertTest.cs b/LinqStudy.Test/LinqToObject/TypeConvertTest.cs new file mode 100644 index 0000000..2bbbfa6 --- /dev/null +++ b/LinqStudy.Test/LinqToObject/TypeConvertTest.cs @@ -0,0 +1,80 @@ +using System; +using System.Collections; +using System.Collections.Generic; +using System.Linq; +using System.Linq.Expressions; +using System.Text; +using System.Data; +using System.Data.SqlTypes; +using System.Data.Common; + +using Xunit; + +namespace LinqStudy.Test.LinqToObject +{ + /// + /// 转换运算符 + /// + public class TypeConvertTest + { + /// + /// AsEnumeralbe: + /// System.Linq.Enumeralbe中,扩展方法 + /// AsEnumeralbe() 是延迟执行 + /// + [Fact] + public void AsEnumeralbe_Test() + { + DataTable dt=new DataTable(); + DataColumn col_id=new DataColumn("Id"); + col_id.AllowDBNull=false; + col_id.AutoIncrementSeed=1; + col_id.AutoIncrement=true; + col_id.AutoIncrementStep=1; + col_id.DataType=typeof(int); + + DataColumn col_name=new DataColumn("Name"); + col_name.AllowDBNull=true; + col_name.AutoIncrement=false; + col_name.DataType=typeof(string); + col_name.DefaultValue=string.Empty; + + DataColumn col_age=new DataColumn("Age"); + col_age.AllowDBNull=false; + col_age.AutoIncrement=false; + col_age.DataType=typeof(int); + col_age.DefaultValue=20; + + dt.Columns.Add(col_id); + dt.Columns.Add(col_name); + dt.Columns.Add(col_age); + + var row_one = dt.NewRow(); + row_one[1]="王高峰"; + row_one[2]=21; + + dt.Rows.Add(row_one); + + var cc = from row in dt.Select() + select row; + var dd = cc.ToList(); + + } + + /// + /// 1.IEnumeralbe 转换为 IQueryable + /// 2.IEnumeralbe 转换为 IQueryable + /// + [Fact] + public void AsQueryable_Test() + { + IEnumerable bb= Enumerable.Range(1,100); + + var cc=bb.AsQueryable(); + + int[] t=new int[]{1,2,3}; + + t.AsEnumerable(); + } + } +}