草庐IT

list-like

全部标签

c# - ActionResult<IEnumerable<T>> 必须返回一个 List<T>

使用ASP.NETCore2.1获取以下代码:[HttpGet("/unresolved")]publicasyncTask>>GetUnresolvedIdentities(){varresults=await_identities.GetUnresolvedIdentities().ConfigureAwait(false);returnresults.ToList();}自从GetUnresolvedIdentities()我就想到了返回IEnumerable我可以返回returnawait_identities.GetUnresolvedIdentities().Configu

c# - AllowUserToAddRows 不适用于 DataGridView 上的 List<> 数据源

我有一个DataGridView与DataSource设置为List但是,当我设置AllowUserToAddRows时,新行指示器不显示至true,当我设置DataSource至BindingList,这似乎解决了问题。问:应该替换我的List与BindingList或者有更好的解决方案? 最佳答案 是否myClass有一个公共(public)的无参数构造函数?如果不是,您可以从BindingList派生并覆盖AddNewCore调用您的自定义构造函数。(edit)或者-只需将您的列表包装在BindingSource中它可能会起作

c# - DDD : Enum like entities

我有以下数据库模型:**Persontable**ID|Name|StateId------------------------------1Joe12Peter13John2**Statetable**ID|Desc------------------------------1Working2Vacation领域模型将是(简化的):publicclassPerson{publicintId{get;}publicstringName{get;set;}publicStateState{get;set;}}publicclassState{privateintid;publicstri

c# - 正确公开 List<T>?

我知道我不应该公开List在一个属性中,但我想知道正确的方法是什么?例如,这样做:publicstaticclassClass1{privatereadonlystaticList_list;publicstaticIEnumerableList{get{return_list;//return_list.AsEnumerable();behavesthesame}}staticClass1(){_list=newList();_list.Add("One");_list.Add("Two");_list.Add("Three");}}将允许我的调用者简单地转换回List:privat

c# - 将 BindingList<MyObject> 转换为 List<MyObject> c#

如何将BindingList转换为List? 最佳答案 试试这个Listlist=yourBindingList.ToList();int是你的类型=) 关于c#-将BindingList转换为Listc#,我们在StackOverflow上找到一个类似的问题: https://stackoverflow.com/questions/10204554/

c# - 两个或多个线程可以毫无问题地迭代同一个 List<t> 吗?

谈论System.Collections.Generic.List在这里。通过下面的例子,Method1和Method2可以在不同的线程上同时执行吗?谢谢classTest{privatereadonlyList_data;publicTest(){_data=LoadData();}privateListLoadData(){//Getdatafromdv.}publicvoidMethod1(){foreach(varlistin_data){//dosomething}}publicvoidMethod2(){foreach(varlistin_data){//dosomethi

c# - 无法在 Visual Studio 2008 中创建 list 资源名称错误

我在Windows窗体应用程序中创建了一个Form1.cs,并且已经有一个文件Form1.resx。但是每当我尝试运行我的应用程序时,我都会不断收到以下错误:Unabletocreateamanifestresourcenamefor"....\gg\Form1.resx".Couldnotfindfile'C:\DocumentsandSettings\Administrator\Desktop\gg\Form1.cs'.谁能告诉我一个原因,我该如何克服我的问题? 最佳答案 您的.csproj已损坏。您需要手动编辑它。对于一个表单

c# - 如何将对象的 List<> 数据绑定(bind)到 DropDownList 并根据对象中的属性设置 SelectedItem?

我如何对List进行数据绑定(bind)将对象添加到DropDownList并根据对象中的属性设置SelectedItem?例如,假设我有一个ListPerson有3个属性...Person.Name(string).Id(int).Selected(bool)我希望第一个Selected==true成为列表中的SelectedItem。 最佳答案 试试这个:Listlist=newList();//populatethelistsomehowif(!IsPostBack){DropDownListddl=newDropDownLi

c# - 将 excel 单元格格式保留为包含 "date like"数据的文本

这看起来很愚蠢,但我无法以#/####的格式获取我的值来编写为文字字符串,而不是在excel中格式化为日期.我正在使用ClosedXML写入excel,并使用以下内容://snipIXLRangeRowtableRow=tableRowRange.Row(1);tableRow.Cell(1).DataType=XLCellValues.Text;tableRow.Cell(1).Value="2/1997";//snip查看我在单元格2/1/1997中获得的输出excel工作表-即使我在代码中将格式设置为文本,我还是将其作为“日期”获取在Excel工作表中-我通过右键单击单元格、设置

c# - 在C#中将DataGridView的内容转换为List

获取DataGridView的内容并将这些值放入C#列表中的最佳方法是什么? 最佳答案 Listitems=newList();foreach(DataGridViewRowdrindataGridView1.Rows){MyItemitem=newMyItem();foreach(DataGridViewCelldcindr.Cells){...buildoutMyItem....basedonDataGridViewCell.OwningColumnandDataGridViewCell.Value}items.Add(item