草庐IT

int_list

全部标签

c# - 无法将带有 [] 的索引应用于 mvc Controller 中类型为“System.Collections.Generic.ICollection<int>”的表达式

publicActionResultaddstandardpackage1(ICollectionSingleStay,ICollectionDOUBLESTAY,ICollectionTRIBLESTAY,ICollectionFAMILYSTAY,ICollectionEXTRABED){vars=SingleStay;for(inti=0;i在for循环中,我收到类似无法将带[]的索引应用于类型表达式的错误,但我需要在for循环中,在我得到的每个中。因为基于for循环,我会将详细信息与其他集合列表绑定(bind)。请帮助我。我在varcal=Singlestay[i]中遇到错误。

c# - Random(int seed) 保证什么?

我正在从事一个项目,该项目依赖于为用户随机分配(没什么花哨的,只是统一的)更大集合的子集。每个用户都有一个从集契约(Contract)构到整数的唯一标识符。据我所知,有两种方法可以做到这一点。在用户和上述较大集合的键控元素之间创建一个数据库连接表,每个用户使用一些函数。这对我的需求来说可能有点不切实际,所以我宁愿做...在运行时通过类似的函数确定子集,但使用唯一的用户ID作为种子值,并且只将集合保存在内存中。下次需要时,它会从更大的集合中再次创建。所以我的问题是,如果我使用.NETRandom对象创建第二个使用user-id作为种子值的函数,Microsoft是否保证以后不会更改Ran

c# - 将填充的 List<BaseClass> 转换为 List<ChildClass>

我有一个List里面有成员。我想将列表(及其所有成员)转换为类型List,其中ChildClass继承BaseClass.我知道我可以通过foreach获得相同的结果:ListChildClassList=newList();foreach(variteminBaseClassList){ChildClassList.Add(itemasChildClass);}但是有没有更简洁的方法呢?注意-这是在WP7平台上完成的。 最佳答案 如果你真的确定所有元素都是可类型转换的,你可以这样做:ChildClassList=BaseClass

c# - 在转换为 int 之前将空字段转换为零?

在我的程序中,我循环遍历数据表以从每个字段获取数据。我的一行代码如下所示:intLYSMKWh=Convert.ToInt32(resultsDT.Rows[currentRow]["LYSMKWh"]);基本上,我只是获取单元格中的值并将其转换为int32。但是,当字段中的数据为空时,我遇到了问题。我收到有关无法将“DBNull”转换为另一种类型的无效转换错误消息。所以,我知道我可以在尝试通过执行以下操作转换它之前检查该字段的值:if(resultsDT.Rows[currentRow]["LYSMKWh"]==null){resultsDT.Rows[currentRow]["LY

c# - LINQ to Entities 无法识别方法 'Int32 ToInt32(System.Object)' 方法,并且无法将此方法翻译成存储表达式

这是我正在尝试做的事情:publicListGetRolesForAccountByEmail(stringemail){varaccount=db.Accounts.SingleOrDefault(a=>a.Email==email);if(account==null)returnnewList();returndb.AccountRoles.Where(a=>a.AccountId==account.AccountId).Select(a=>Convert.ToInt32(a.RoleId)).ToList();}我必须转换为Int32,因为我无法返回List当方法返回List时.

c# - 如何将 DataSource 转换为 List<T>?

我有以下在DataGridView上加载产品的方法privatevoidLoadProducts(Listproducts){Source.DataSource=products;//SourceisBindingSourceProductsDataGrid.DataSource=Source;}现在我正试图将它们还给我以保存它们,如下所示。privatevoidSaveAll(){Repositoryrepository=Repository.Instance;Listproducts=(List)Source.DataSource;Console.WriteLine("Estees

c# - 我怎么能在int上执行方法?在没有 NullReferenceException 的情况下设置为 null?

我在MSDN上读到:Thenullkeywordisaliteralthatrepresentsanullreference,onethatdoesnotrefertoanyobject.但是我看到下面的代码运行时没有抛出任何异常:int?i=null;vars=i.ToString();那么如果变量i为null,为什么我可以执行它的方法呢? 最佳答案 因为int?实际上是一个Nullable和Nullable是struct,和一个结构cannotbenull.就是这样Nullabletypeswork.它们不是引用值,所以它们不能

c# - 如何并行启动 List<Task>?

我有一个返回System.Threading.Tasks.Task的对象:publicclassMyClass{publicTaskGetTask(objectstate,CancellationTokencancellationToken){returnnewTask(Execute,state,cancellationToken);}publicvoidExecute(objectcontext){//dostuff}}在其他地方我有一个List,所以我执行以下操作以获得List:varmyTaskList=myClassList.Select(p=>p.GetTask(null,

c# - 'System.Collections.Generic.List<float >' does not contain a definition for ' Sum'

我正在尝试使用内置的Sum()函数对float列表求和,但我不断收到此错误:ErrorCS1061:'System.Collections.Generic.List'doesnotcontainadefinitionfor'Sum'andnoextensionmethod'Sum'acceptingafirstargumentoftype'System.Collections.Generic.List'couldbefound(areyoumissingausingdirectiveoranassemblyreference?)(CS1061)我有usingSystem.Collect

c# - 无法将类型 '.List<AnonymousType#1>' 隐式转换为 '.List<WebApplication2.Customer>'

在以下返回列表的代码中:publicListGeAllCust(){varresults=db.Customers.Select(x=>new{x.CustName,x.CustEmail,x.CustAddress,x.CustContactNo}).ToList()returnresults;}我收到C#无法转换列表的错误报告:Error:CannotimplicitlyconverttypeSystem.Collections.Generic.ListtoSystem.Collections.Generic.List这是为什么?下面的屏幕截图显示了VisualStudio在错误的