generic-list

C# exposing class to COM - Generic Collections

拟墨画扇 提交于 2019-11-29 08:18:49
We have a small framework written in C# .Net 2.0 that we want to expose to COM. Problem is, we have some generic classes that would be exposed as the following: interface IOurClass { ReadonlyCollection<IOurListObject> OurCollection { get; } } interface IOurListObject { //Some properties that don't matter } What is the best (or recommended way) to expose generic collections to COM? We do not have to support generics, we just need to somehow expose a collection of IOurListObject. We also would like to avoid having to write a new class for every collection we use, but it may not be possible. It

c# array vs generic list [duplicate]

本小妞迷上赌 提交于 2019-11-28 22:34:08
This question already has an answer here: Array versus List<T>: When to use which? 15 answers i basically want to know the differences or advantages in using a generic list instead of an array in the below mentioned scenario class Employee { private string _empName; public string EmpName { get{ return _empName; } set{ _empName = value; } } } 1. Employee[] emp 2. List<Employee> emp can anyone please tell me the advantages or disadvantages and which one to prefer? One big difference is that List<Employee> can be expanded (you can call Add on it) or contracted (you can call Remove on it) whereas

Convert an enum to List<string>

寵の児 提交于 2019-11-28 17:41:52
How do I convert the following Enum to a List of strings? [Flags] public enum DataSourceTypes { None = 0, Grid = 1, ExcelFile = 2, ODBC = 4 }; I couldn't find this exact question, this Enum to List is the closest but I specifically want List<string> DCShannon Use Enum 's static method, GetNames . It returns a string[] , like so: Enum.GetNames(typeof(DataSourceTypes)) If you want to create a method that does only this for only one type of enum , and also converts that array to a List , you can write something like this: public List<string> GetDataSourceTypes() { return Enum.GetNames(typeof

C# List<double> size vs double[] size

谁说我不能喝 提交于 2019-11-28 13:44:24
So I just was testing the CLR Profiler from microsoft, and I did a little program that created a List with 1,000,000 doubles in it. I checked the heap, and turns out the List<> size was around 124KB (I don't remember exactly, but it was around that). This really rocked my world, how could it be 124KB if it had 1 million doubles in it? Anyway, after that I decided to check a double[1000000]. And to my surprise (well not really since this is what I expected the with the List<> =P), the array size is 7.6MB. HUGE difference!! How come they're different? How does the List<> manage its items that it

How to convert DataTable to object type List in C# [closed]

瘦欲@ 提交于 2019-11-28 11:48:24
I want to convert DataTable to List<object> in C#. Here is my code. But it is not working. Please help me public List<object> ShowMessage() { List<object> obj = new List<object>(); DataTable dt = new DataTable(); dt.Columns.Add("ID"); dt.Columns.Add("Name"); dt.Rows.Add("1","AAA"); dt.Rows.Add("2", "BBB"); dt.Rows.Add("3", "CCC"); foreach (DataRow dr in dt.Rows) { obj.Add(dr); } return obj; } This is the Error-- Neeraj Kumar Gupta If you have any Typed DataType for list object something like this public class MyObj { public string Name { get; set; } public int ID { get; set; } } then you can

Generic list by using reflection

时间秒杀一切 提交于 2019-11-28 11:37:56
I have a scenario on which i got Class name as a string I just want to create a generic List of that class. I tried the following Type _type = Type.GetType(className); List<_type> list = new List<_type>(); But iam geting error . I can't gave that _type as list argument. If anybody knows please help me Closest you can get: Type listType = typeof(List<>).MakeGenericType(_type); IList list = (IList) Activator.CreateInstance(listType); Reflection takes place during runtime, as the type of an object could be changed to anything by a running program. Type parameters (generics), on the other hand,

How to cast or convert List of objects to queue of objects

流过昼夜 提交于 2019-11-28 09:38:43
How can one convert a list of objects to a queue thereby maintaining the same order? Queue has a constructor that takes in an ICollection . You can pass your list into the queue to initialize it with the same elements: var queue = new Queue<T>(list); // where 'T' is the lists data type. What do you mean by "the same order?" If you do this: var queue = new Queue<object>(list); Then the queue will be enumerated over in the same order as the list, which means that a call to Dequeue would return the element that had previously resided at list[0] . If you do this: var queue = new Queue<object>(list

How can i sort Generic list with Linq?

喜夏-厌秋 提交于 2019-11-28 08:29:28
问题 How can i sort myScriptCellsCount.MyCellsCharactersCount (list int type) in linq public class MyExcelSheetsCells { public List<int> MyCellsCharactersCount { get; set; } public MyExcelSheetsCells() { MyCellsCharactersCount = new List<int>(); } } void ArrangedDataList(DataTable dTable) { DAL.MyExcelSheets myexcelSheet = new DAL.MyExcelSheets(); myScriptCellsCount = new TestExceltoSql.DAL.MyExcelSheetsCells(); foreach (DataColumn col in dTable.Columns) myexcelSheet.MyColumnNames.Add(col

Converting a List of Base type to a List of Inherited Type

╄→尐↘猪︶ㄣ 提交于 2019-11-28 08:18:20
I would be certain that this question addresses something that would have been brought up in a previous question, but I was unable to find it. There is a method in a C# class that takes as a parameter a generic List of a Base Class. I need to pass a list of an inherited class and do not know exactly how to do this. I am getting an error in my attempts. Below is sample code to illustrated this: public class A { public static void MethodC(List<A>) { // Do Something here with the list } } public Class B : A { // B inherits from A, A is the Base Class } // Code utilizing the above method List<B>

C# exposing class to COM - Generic Collections

北城余情 提交于 2019-11-28 01:44:42
问题 We have a small framework written in C# .Net 2.0 that we want to expose to COM. Problem is, we have some generic classes that would be exposed as the following: interface IOurClass { ReadonlyCollection<IOurListObject> OurCollection { get; } } interface IOurListObject { //Some properties that don't matter } What is the best (or recommended way) to expose generic collections to COM? We do not have to support generics, we just need to somehow expose a collection of IOurListObject. We also would