generic-list

Cloned Cached item has memory issues

Hi there, we are having values stored in Cache-Enterprise library Caching Block. The accessors of the cached item, which is a List, modify the values. We didnt want the Cached Items to get affected. Hence first we returned a new List(IEnumerator of the CachedItem) This made sure accessors adding and removing items had little effect on ...

WCF: Serializing and Deserializing generic collections

I have a class Team that holds a generic list: [DataContract(Name = "TeamDTO", IsReference = true)] public class Team { [DataMember] private IList<Person> members = new List<Person>(); public Team() { Init(); } private void Init() { members = new List<Person>(); } [System.Runtime.Se...

.NET XmlSerializer fails with List<T>

I'm using a singleton class to save all my settings info. It's first utilized by calling Settings.ValidateSettings(@"C:\MyApp"). The problem I'm having is that 'List Contacts' is causing the xmlserializer to fail to write the settings file, or to load said settings. If I comment out the List<T> then I have no problems saving/loading the...

Fastest way to check a List<T> for a date

I have a list of dates that a machine has worked on, but it doesn't include a date that machine was down. I need to create a list of days worked and not worked. I am not sure of the best way to do this. I have started by incrementing through all the days of a range and checking to see if the date is in the list by iterating through the e...

How to OrderBy on a generic IEnumerable (IEnumerable<T>) using LINQ in C#?

In my generic repository I have below method: public virtual IEnumerable<T> GetAll<T>() where T : class { using (var ctx = new DataContext()) { var table = ctx.GetTable<T>().ToList(); return table; } } T is a Linq to Sql class and I want to be able to OrderBy on a particular property (i.e. int SortOrder). S...

Thread Safety of C# List<T> for readers

I am planning to create the list once in a static constructor and then have multiple instances of that class read it (and enumerate through it) concurrently without doing any locking. In this article http://msdn.microsoft.com/en-us/library/6sh2ey19.aspx MS describes the issue of thread safety as follows: Public static (Shared in Vi...

Generic List<T> as IEnumerable<object>

I'm trying to do cast a List to an IEnumerable, so I can verify that different lists are not null or empty: Suppose myList is a List < T > . Then in the caller code I wanted: Validator.VerifyNotNullOrEmpty(myList as IEnumerable<object>, @"myList", @"Clas...

Issue converting Sitecore Item[] using ToList<T>

Working with Sitecore and Linq extensions. I am trying to convert to from an item array to the list using the following piece of code: Item variationsFolder = masterDB.SelectSingleItem(VariationsFolderID.ToString()); List<Item> variationList = variationsFolder.GetChildren().ToList<Item>(); However I keep getting this error whenever I...

Question about using Anonymous List Types

private List<T> GetFieldList() { var Fields = new { DisplayName = "MCP", FieldName = "t.MCP", FieldType = 1 }; var FieldList = (new[] { Fields }).ToList(); return FieldList; } Should I be able to do something like this? ...

Is there something like List<String, Int32, Int32> (multidimensional generic list)

I need something similar to List<String, Int32, Int32>. List only supports one type at a time, and Dictionary only two at a time. Is there a clean way to do something like the above (a multidimensional generic list/collection)? ...

what is the best way to analyze user raw query and detect what who want to search

hi, i am developing a very basic prototype of web search engine and now i want to know what is the best way to analyze user raw query and detect what who want to search. like Google, Bing, Yahoo etc... an example user raw query is something like this: Google+Maps+"South+Africa"+Brazil+OR+Italy+OR+Spain+-Argentina+Netherlands and i wa...

How can i sort Generic list with Linq?

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(DataTabl...

convert .NET generic List to F# list

Is there a built-in method to convert the .NET List<> into the F# list? ...

How do I filter a generic list in .Net2.0?

Hi, I am using asp.net 2.0 and C#. I have a generic list, List<EmployeeInfo> empInfoList; this list is loaded with the employee information. Now, I want to filter this list with the textbox value. Which is "EmploeeName". I have to filter this list with the employeeName, and bind it to the gridview again. I am not sure how can I...

How to sort the list with duplicate keys?

I have a set of elements/keys which I'm reading from two different config files. So the keys may be same but with different values associated with each of them. I want to list them in the sorted order. What can I do ? I tried with SortedList class but it does not allow duplicate keys. How can I do it? e.g Lets say I have 3 elements wi...

Set Binding Source DataSource to Generic IList<> Error

If I want to set the DataSource property on a BindingSource to an IList<>, do I need an explicit cast as the following error message says or am I doing something wrong? interface IView { IList<OrderItems> BindingSource { get; set;} } public partial class Form1 : Form, IView { public Form1() {...

Convert generic IList<CustomType> to array?

Hello, I have an IList which contains a custom type. One of the properties of that custom type is called ID. How could I convert that without using a for loop? The array should not be of the CustomType, but if the type of ID, which is int. Thanks! ...

Convert list of one type to list of another type in C# 3.5

I have an object, with ID and Name properties. I have a list of the objects, but I want to convert it to a list of strings containing the name of the object. I'm guessing there's some fancy Linq method that will put the name of the object into the list. List<string> myObjectNames = myObjectList.? ...

C#: Why return a collection interface rather than a concrete type?

I've noticed in other people's code that methods returning generic collections will almost always return an interface (e.g. IEnumerable or IList) rather than a concrete implementation. I have two related questions. Firstly, why (if at all) is it considered better to return an interface? Secondly, is there a collection interface that inc...

C#: returning an inherited class from an instance of its base class (generic list)

This is probably me just remembering things completely backwards, but I'd like to know more about what I'm doing wrong... I have declared a class to be nothing more than a direct inheritance from a generic list (done to simplify naming), something like this: public class FooList : List<Foo> {} now in another method completely separat...