草庐IT

this-is-a-collection

全部标签

c# - 数据库错误 : There is no row at position 0

我相信几个月前有人问过这个问题,但我相信我的情况不同,同样的规则可能不适用。每次我执行这个方法都会弹出同样的错误。位置0处没有行。如果我将[0]更改为[1]或[15];[1]等处没有行。这是否意味着我的数据库甚至没有连接?我是否应该编写某种if语句来确定检查行是否存在?publicboolUpdateOrderToShipped(stringorder){orderNumber=order;stringbatch=ConfigurationManager.AppSettings["SuccessfulOrderBatch"];stringstatement="UPDATESOP1010

c# - 检查 Collection 中的所有项目是否具有相同的值

名为MeasurementCollection的集合的扩展方法检查每个项目的属性Template.Frequency(Enum)是否具有相同的值。publicstaticboolIsQuantized(thisMeasurementCollectionitems){return(fromiinitemsselecti.Template.Frequency).Distinct().Count()==1;}编辑关于底层类的信息MeasurementCollection:ICollectionIMeasurement{IMeasurementTemplateTemplate{get;}...

c# - 无效操作异常 : No IAuthenticationSignInHandler is configured to handle sign in for the scheme: MyCookieAuthenticationScheme

我正在尝试按照说明进行操作here将Cookie身份验证添加到我的网站。到目前为止,我添加了以下内容:InvoketheUseAuthenticationmethodintheConfiguremethodoftheStartup.csfile:app.UseAuthentication();InvoketheAddAuthenticationandAddCookiemethodsintheConfigureServicesmethodoftheStartup.csfile:services.AddAuthentication("MyCookieAuthenticationScheme

c# - 等于 System.Collections.Generic.List<T>... 的方法?

我正在创建一个派生自List的类...publicclassMyList:List{}我已经覆盖了MyListItem的Equals...publicoverrideboolEquals(objectobj){MyListItemli=objasMyListItem;return(ID==li.ID);//IDisapropertyofMyListItem}我也想在MyList对象中有一个Equals方法,它将比较列表中的每个项目,在每个MyListItem对象上调用Equals()。简单地调用...会很好MyListl1=newMyList(){newMyListItem(1),ne

c# - : this() As a constructor

我正在尝试更好地理解一般实践...特别是在构造函数中派生this()。我知道它的代码较少,但我认为它的可读性较差。这样做是常见的/好的做法吗?还是编写第二个专门处理它的构造函数更好?publicSomeOtherStuff(stringrabble):this(rabble,"bloop"){}或PublicSomeOtherStuff(stringrabble){//setbloop}任何输入将不胜感激 最佳答案 最好尽可能使用this()。否则你将复制一些代码,这违反了DRY(不要重复自己)原则。重复自己的问题在于,每次您需要进

c# - 委托(delegate)给实例方法不能有 null 'this'

我正在开发一个C#.NET2.0应用程序,其中在运行时根据环境加载两个DLL之一。两个DLL包含相同的函数,但它们没有链接到相同的地址偏移量。我的问题是关于我的应用程序代码中的函数委托(delegate)。publicclassMyClass{publicdelegateintMyFunctionDelegate(int_some,string_args);publicMyFunctionDelegateMyFuncToCallFrmApp;publicMyClass():base(){this.MyFuncToCallFrmApp=newMyFunctionDelegate(this

c# -/平台 :anycpu32bitpreferred is not a valid setting for option/target:library or/target:module

我创建了一个Windows服务项目,后来决定将其输出类型更改为类库,这样我就可以将服务类包含在另一个项目中,该项目将创建要作为服务安装的.exe。但是现在,当我尝试构建第一个项目时,它失败并出现错误:/platform:anycpu32bitpreferredisnotavalidsettingforoption/target:libraryor/target:module我该如何解决这个问题? 最佳答案 尝试卸载项目(在解决方案资源管理器中右键单击)编辑.csproj(右键单击解决方案资源管理器)删除true重新加载项目。

c# - 可以锁定 System.Collections.Generic.List<t> 吗?

我一直在阅读有关syncroot元素的信息,但我在List类型中找不到它。那么System.Collections.Generic.List类型应该如何进行多线程同步呢? 最佳答案 你找不到它的原因是因为它是explicitlyremoved.如果它真的是你想做的,使用SynchronizedCollection或者创建一个专用的同步对象。最好的方法(通常)是创建一个专用的同步对象,正如Winston所说明的那样。SyncRoot的本质问题特性是它提供了一种错误的安全感——它只能处理非常有限的情况。开发人员经常忽略整个逻辑操作的同步

c# - 为什么我会收到 "The modifier ' virtual'is not valid for this item“错误?

我正在尝试使用以下模型创建mvc应用程序:(代码很大。我认为它对您来说更容易理解)publicclassJob{publicintJobId{get;set;}publicstringName{get;set;}publicListGetJobs(){ListjobsList=newList();jobsList.Add(newJob{JobId=1,Name="Operator"});jobsList.Add(newJob{JobId=2,Name="Performer"});jobsList.Add(newJob{JobId=3,Name="Head"});returnjobsLi

c# - Xunit.Assert.Collection 中的问题 - C#

我有一个类库,它包含以下模型和方法型号:publicclassEmployee{publicintEmpId{get;set;}publicstringName{get;set;}}方法:publicclassEmployeeService{publicListGetEmployee(){returnnewList(){newEmployee(){EmpId=1,Name="John"},newEmployee(){EmpId=2,Name="AlbertJohn"},newEmployee(){EmpId=3,Name="Emma"},}.Where(m=>m.Name.Contai