如果在开发的时候遇到非泛型 类型"IEnumerable"不能与类型参数一起使用,那么就是变量的命名空间没弄对 在 dotnet 里面有 System.Collections.IEnumerable 和 System.Collections.Generic.IEnumerable<> 两个不同的类,带泛型的需要在 System.Collections.Generic 命名空间找到 如果是写了 System.Collections.IEnumerable<Foo>…
title author date CreateTime categories dotnet 非泛型 类型 System.Collections.IEnumerable 不能与类型实参一起使用 lindexi 2019-08-31 16:55:59 +0800 2019-04-12 10:24:26 +0800 dotnet 如果在开发的时候遇到非泛型 类型"IEnumerable"不能与类型参数一起使用,那么就是变量的命名空间没弄对 在 dotnet 里面有 System.Colle…
API有一个需要实现的抽象方法: public IList<IPermission> GetPermissions(); 需要注意的是IList<IPermission>这个泛型集合的类型参数IPermission是个接口. 现在我要在实现类中使用NHibernate去实现这个方法,一开始我觉得很简单. 因为有一个实体类Permission实现了IPermission接口,于是很直接的写法: return NHibernateSession.CreateCriteria(typeo…
在WPF中DataGrid 选择事件中获取SelectedItems 报错如下 无法将类型为“System.Windows.Controls.SelectedItemCollection”的对象强制转换为类型“System.Collections.Generic.IList`1[SomeModel]”. 应该如此使用 System.Collections.IList items = (System.Collections.IList)this.dataGrid.SelectedItems;  …
无法将类型“System.Collections.Generic.List<anonymous type:string ClassID,string ClsssName>”隐式转换为“System.Collections.Generic.List<Ecology.Model.EnergyFlowGraph>” 一.EF应用中,常见类型转换问题解决方案 public List<EnergyFlowGraph> GetData() { var data = db.Energ…
在一个项目中使用LINQ和EF时出现了题目所示的异常,搜索了很多资料都找不到解决办法,主要是因为EF方面的知识欠缺. 先将情况记录如下,以供以后参考. 查询主要设计两张表,由外键关联: 在进行下面的查询时,出现异常:无法将类型“System.Nullable`1”强制转换为类型“System.Object”.LINQ to Entities 仅支持强制转换 EDM 基元或枚举类型. public ActionResult GetIpSegments() { //List<Ipsegment>…
解决办法:添加 using System.Collections:命名空间…
List<Model.Template> templateList = templateBLL.RecommendTemplateByOrder(modelEbay); List<Model.TemplateInfo> recommandlist = templateList.Select(m => new Model.TemplateInfo                {                    AccountId = m.AccountID,      …
IEnumerator和IEnumerable的作用 其实IEnumerator和IEnumerable的作用很简单,就是让除数组和集合之外的类型也能支持foreach循环,至于foreach循环,如果不清楚,请参考C# foreach循环较for循环的优势与劣势 代码如下: static void Main(string[] args) { CatList cats = new CatList(); foreach (var cat in cats) { Console.WriteLine(c…
一.定义泛型类 void Main() { //实例化泛型类时,才指定具体的类型 MyGenericClass<); Console.WriteLine(MyGeneri.InnerT1Object * ); } public class MyGenericClass<T>//<T1,T2,T3>表示多个类型参数 { private T innerT1Object; public string LastName; public MyGenericClass(T item)//…
在使用C#写Web Service时遇到了个很奇怪的问题.返回值的类型是泛型(我用的是类似List<string>)的接口,测试时发现总是报什么无法转换为对象的错误,百思不得其解. 后来在同事的帮助下,发现了规律,在返回值是泛型的接口前面,只要有返回值是字符串数组的接口,就会发生错误,如果把返回泛型的接口放到返回字符串数组的接口后面,就没问题了. 结合代码说明一下,代码如下: [WebMethod] public string[] HelloWorld1() { ]; str[] = &quo…
1. array是一个固定长度的,如果要动态的存储的话就不行了,虽然 System.Collections.ArrayList(),是一个动态的存储的容器,但是没有对存储中的数据进行一个约束,所以非泛型的容器和泛型 的容器相比存在两个问题:                          1.性能问题:                          2.安全问题:================================================================…
#region Linq to 集合查询非泛型集合要指定Student类型            //ArrayList list = new ArrayList();            //list.Add(new Student { Name = "Tom", Age = 17 });            //list.Add(new Student { Name = "Jerry", Age = 16 });            //list.Add(…
&apos;System.Collections.Generic.IEnumerable<string>&apos; does not contain a definition for &apos;Where&apos; and no extension method &apos;Where&apos; accepting a first argument of type &apos;System.Collections.Generic.…
System.Collections命名空间包含可使用的集合类和相关的接口,提供了集合的基本功能. 该命名空间下的.NET非泛型集合类如下所示: — System.Collections.ArrayList:数组集合类,使用大小可按动态增加的数组实现Ilist接口.— System.Collections.BitArray:布尔集合类,管理位值的压缩数组,该值为布尔值.— System.Collections.Queue:队列,表示对象的先进先出集合.— System.Collections.S…
public class CommonClass { public static void ShowInt(int iValue) { //typeof(CommonClass) typeof关键字 获取一个类型的类型 Console.WriteLine(" ShowInt方法 展示{0},其类型为{1}", iValue, typeof(int)); } public static void ShowLong(long lValue) { //lValue.GetType() 变量.…
C# 泛型集合之非泛型集合类与泛型集合类的对应: ArrayList对应List HashTable对应Dictionary Queue对应Queue Stack对应Stack SortedList对应SortedList 第一  : ArrayList(非泛型集合)  与List(泛型集合) ArrayList 是数组的复杂版本.ArrayList 类提供在大多数 Collections 类中提供但不在 Array 类中提供的一些功能: 1.Array 的容量是固定的,而 ArrayList…
前言: 本人调式npoi导入.导出试用成功后,引入到项目中,导入完美运行,但是导出怎么样都看不到现在的页面,而且浏览器和后台都没有报任务错误,让人好事纳闷,后来去调式,发现在除了一个IsReadOnly = "book.IsReadOnly"引发了类型"System.NotImplementedException"的异常).最开始的怀疑是这里问题,然后去调式环境看也是存在的,然后就自然想到的前端问题.最后果然是前端出了问题,在导出的点击函数里写了异步ajax蠢死了,…
来自:http://blog.csdn.net/jiayanhui2877/article/details/7623845 C# 泛型集合之非泛型集合类与泛型集合类的对应: ArrayList对应List HashTable对应Dictionary Queue对应Queue Stack对应Stack SortedList对应SortedList C# 集合类 Array Arraylist List Hashtable Dictionary Stack Queue 1.数组是固定大小的,不能伸缩…
建议20:使用泛型集合代替非泛型集合 在建议1中我们知道,如果要让代码高效运行,应该尽量避免装箱和拆箱,以及尽量减少转型.很遗憾,在微软提供给我们的第一代集合类型中没有做到这一点,下面我们看ArrayList这个类的使用情况: ArrayList al=new ArrayList(); al.Add(); al.Add(); al.Add("mike"); foreach (var item in al) { Console.WriteLine(item); } 上面这段代码充分演示了…
第一  : ArrayList(非泛型集合)  与List(泛型集合) ArrayList 是数组的复杂版本.ArrayList 类提供在大多数 Collections 类中提供但不在 Array(数组.Array 类提供了各种用于数组的属性和方法.) 类中提供的一些功能: 1.Array 的容量是固定的,而 ArrayList 的容量是根据需要自动扩展的. 2.ArrayList 提供添加.插入或移除某一范围元素的方法.在 Array 中,您只能一次获取或设置一个元素的值. 3.使用 Sync…
几张图就可以说明一切 2015-03-29 21:54:09,206 [77] ERROR log - System.NotSupportedException: 无法将类型“System.DateTime”强制转换为类型“System.Object”.LINQ to Entities 仅支持强制转换 EDM 基元或枚举类型. 在 System.Data.Entity.Core.Objects.ELinq.ExpressionConverter.ValidateAndAdjustCastType…
一.问题起源 LINQ to object在设计时,是配合IEnumerable<T>接口的泛型集合类型使用的,例如字典.数组.List<T>等,但是对于继承了IEnumerable的非泛型集合如何处理,例如ArrayList. 二.解决办法 上源码: ArrayList mArrayList = ","1dsadsad","12w1212","1212e12esadq" }; var query = from…
可以利用反射将DataTable转换为List<T>对象:原始链接http://www.jb51.net/article/67386.htm 但是该方法在DataTable里某个字段类型是Int32会有问题,报异常:类型“System.Int64”的对象无法转换为类型“System.Int32”. 可在赋值的时候加一句: if(pi.GetMethod.ReturnParameter.ParameterType.Name == "Int32") { value = Conv…
System.collection类: 动态数组ArrayList 代表了可被单独索引的对象的有序集合.也就是说他是一个动态的数组,你可以通过索引来进行增删改等操作,数组会自动调整数组的大小.允许在列表进行动态内存的分配.增加.收索和排序. Capacity:获取或设置 ArrayList 可以包含的元素个数.Count:获取 ArrayList 中实际包含的元素个数.IsFixedSize:获取一个值,表示 ArrayList 是否具有固定大小.IsReadOnly:获取一个值,表示 Arra…
非泛型集合的类和接口位于System.Collections命名空间 如:列表.队列.位数组.哈希表和字典的集合     ArrayList 动态数组 可被单独索引的对象的有序集合可以使用索引在指定的位置添加和移除项目,动态数组会自动重新调整它的大小允许在列表中进行动态内存分配.增加.搜索.排序   Capacity:获取或设置可以包含的元素个数Count:包含的元素个数Item:获取或设置置顶索引处的元素Add:末尾添加一个对象Clear:移除所有的元素Contains:判断元素是否在Arra…
System.Collections 名称空间中的几个接口提供了基本的组合功能: IEnumerable 可以迭代集合中的项. ICollection(继承于IEnumerable)可以获取集合中项的个数,并能把项复制到一个简单的数组类型中. IList(继承于IEnumerable 和ICollection)提供了集合的项列表,允许访问这些项,并提供其他一些与项列表相关的基本功能. IDictionary(继承于IEnumerable 和ICollection)类似于IList,但提供…
using System; using System.Collections.Generic; public class Example { public static void Main() { // Create a new dictionary of strings, with string keys. // Dictionary<string, string> openWith = new Dictionary<string, string>(); // Add some…
using System; using System.Collections; public class SamplesArrayList { public static void Main() { // Creates and initializes a new ArrayList. ArrayList myAL = new ArrayList(); myAL.Add("Hello"); myAL.Add("World"); myAL.Add("!&qu…