请参阅System.Array类的定义
public abstract class Array : IList, ...
从理论上讲,我应该能够写下这一点,并感到高兴
int[] list = new int[] {};
IList iList = (IList)list;
我也应该可以从iList中调用任何方法
 ilist.Add(1); //exception here
我的问题不是为什么我得到一个例外,而是为什么Array实现了IList?
上面两个有什么区别?
你能帮我理解这两者之间的实际差异吗?
IList<int> myList = new List<int>();
List<int> myList = new List<int>();
我有这样的代码:
void Foobar(string[] arr, Dictionary<string, string[]>)
{
   var t = arr.Intersect(dic.Keys).ToList(); // .or ToArray() ?
   foreach(var item in t)
   {
      ..
   }
   var j = t.Count; // also I need this
}
哪种方法更受欢迎?
我可以没有任何东西,但我需要知道大小,我不想打电话Enumerable.Count<T>()- 似乎做了更多的行动然后Array<T>.Size或List<T>.Count.我对吗?
抱歉这个模糊的问题,但我一直在寻找一天中最好的部分,我已经阅读了一篇文章(这里有很多问题)但是找不到一个容易理解的答案.
我(我想)知道IEnumerable的用途,但我无法理解用泛型类型参数定义它意味着什么,例如:
IEnumerable<int> test = method();
这只是让我发疯!请让我摆脱痛苦并解释它意味着什么?
我们在LINQ中有这个数组.
string[] colors = { "green", "brown", "blue", "red" };
这段代码返回0.
var list = new List<string>(colors);
IEnumerable<string> q3 = list.Where(c => c.Length == 3);
list.Remove("red");
listBox1.Items.Add("Oh! That is : " + q3.Count());
和其他返回1.
var list = new List<string>(colors);
List<string> q3 = list.Where(c => c.Length == 3).ToList();
list.Remove("red");
listBox1.Items.Add("Oh! That is : " + q3.Count());
为什么会这样?列表和Ienumerable之间的差异是什么?
我定义了一个新的 ViewModel 类,如下所示:-
public class myviewmodel
{
    public IEnumerable<Question> Questions { get; set; }
    public decimal Total { get; set; }
    public string Message { get; set; }
}
但我也可以将其定义为
public class myviewmodel
{
    public List<Question> Questions { get; set; }
    public decimal Total { get; set; }
    public string Message { get; set; }
}
如果我想创建一个新的模型类,也会发生这种情况;那么这两种方法有什么区别呢?BR
使用它有什么好处
 private static IEnumerable<string> GetColumnNames(this IDataReader reader)
        {
             for (int i = 0; i < reader.FieldCount; i++)
                yield return reader.GetName(i);
        }
而不是这个
  private static string[] GetColumnNames(this IDataReader reader)
    {
        var columnNames = new string[reader.FieldCount];
        for (int i = 0; i < reader.FieldCount; i++)
             columnNames[i] = reader.GetName(i);
        return columnNames;
    }
这是我如何使用这种方法
    int  orderId = _noOrdinal;
    IEnumerable<string> columnNames = reader.GetColumnNames();
    if (columnNames.Contains("OrderId"))
           orderId = reader.GetOrdinal("OrderId");
     while (reader.Read())
            yield return new BEContractB2CService
                     {
                         //..................
                         Order = new BEOrder
                          {  Id = orderId == …我应该IEnumerable<T>只在懒惰评估的情况下从方法和属性返回吗?
你有任何人的模式,当你返回IEnumerable,ICollection和IList?
我正在制作一个自定义网格,接受IEnumerable作为Itemsource.但是我在删除方法期间无法删除itemsource中的Item.你们能帮我使用下面的代码吗?
static void Main(string[] args)
{
    List<MyData> source = new List<MyData>();
    int itemsCount = 20;
    for (int i = 0; i < itemsCount; i++)
    {
       source.Add(new MyData() { Data = "mydata" + i });
    }
    IEnumerable mItemsource = source;
    //Remove Sample of an mItemSource
    //goes here ..
}
public class MyData { public string Data { get; set; } }
当我在 Select() 语句的末尾添加 .ToList() 时,它按预期工作。在这种情况下,IEnumerable 和 List 之间有什么区别?
class Foo{
    public string Name { get; set; }
    public Guid Id { get; set; }
}
class Program
{
    static void Main(string[] args)
    {
        var list = new List<string>(){ "first", "last" };
        var bar = list.Select(x => new Foo {
            Name = x,
            Id = Guid.NewGuid()
        }); //.ToList();
        Console.WriteLine("bar Count = " + bar.Count());
        Console.WriteLine();
        for (int i = 0; i < 3; i++) { 
            Console.WriteLine(bar.First().Name + " " + bar.First().Id); …这里我有两个表有一些列.这里我的目标是我想使用ChilsMaster进行GroupBy操作
public partial class Master
{
    public int MasterId { get; set; }
    public string Prod_Name { get; set; }
    public string Produ_Adress { get; set; }
    public Nullable<decimal> Price { get; set; }
}
public partial class ChildMasterMaster
{
    public int ChildId { get; set; }
    public Nullable<int> MasterId { get; set; }
    public string SalesRec { get; set; }
    public Nullable<bool> Prod_Deliver { get; set; }
}
public class Market_Masters
{    
    public int MasterId { get; set; } …c# ×12
ienumerable ×4
linq ×3
list ×3
.net ×2
arrays ×2
.net-4.0 ×1
.net-core ×1
collections ×1
generics ×1
ilist ×1
liskov-substitution-principle ×1
performance ×1
syntax ×1