generic-list

Two list synchronization

ε祈祈猫儿з 提交于 2019-12-06 16:08:21
I'm doing the synchronization between the two lists. IList<Event> GoogleEvents and Table<myEvent> DB.Events; On google side i'm using this String Summary, String Description, EventDateTime Start, EventDateTime End, Event.RemindersData Reminders; On db side like this my code is like this foreach (myEvent item in DB.Events) { if (item.GoogleID == "" || item.GoogleID == null)// i add event my db { //Add dbEvent to google and save id to googleid column } } foreach (Event item in myGoogleCalendar.Items) { if (DB.Events.Where(o => o.GoogleID == item.Id).Count() == 0)// i add event google { //Add

Count items in List(Of structure) using predicate in .NET 2.0/VB.NET

半腔热情 提交于 2019-12-06 14:52:51
I need to count the items that meet a criteria in a List(Of Structure) in .NET 2.0. For example: Dim listcars as New List(Of car) Structure car Dim Name as String Dim year as Integer End structure Now I need to count all cars with name Toyota, etc.. How do I do it? You want List.LongCount . Dim CarList As New List(Of Car) Dim Model As String = "Toyota" Dim ToyotaCount As Long = CarList.LongCount(Function(car) car.Name = Model) Dim toyotas As Integer = carList.Count(Function(c) c.Name = "Toyota") Here you go. var count = carList.Count(x => x.Name == "Toyota"); The syntax is blatantly wrong, but

How to use XMLSerializer with a Castle ActiveRecord containing an IList<T> member

限于喜欢 提交于 2019-12-06 06:18:46
问题 I am trying to use the XMLSerializer with a castle active record class which looks like the following: [ActiveRecord("Model")] public class DataModel : ActiveRecordBase { private IList<Document> documents; [XmlArray("Documents")] public virtual IList<Document> Documents { get { return documents; } set { documents = value; } } } However, the XMLSerializer runs into trouble because of the IList interface. (Raises exception: Cannot serialize member 'DataModel.Documents' of type 'System

How make custom Thread Safe Generic List return the whole list in C#?

和自甴很熟 提交于 2019-12-05 10:20:57
I am a threading noob and I am trying to write a custom thread safe generic list class in C# (.NET 3.5 SP1). I've read Why are thread safe collections so hard? . After reviewing the requirements of the class I think I only need to safely add to the list and return the list. The example shows pretty much all I want except it lacks the return list method therefore I've written my own public method like below: Update: based on suggestions given I've reviewed my requirements and therefore simplified the class to as below: public sealed class ThreadSafeList<T> { private readonly IList<T> list = new

serialize/deserialize List<T> to JSON

纵饮孤独 提交于 2019-12-04 12:31:27
问题 I want to be able to serialize/deserialize a generic list what I so far is this public static string ToJson(this object obj, int recursionDepth = 100) { JavaScriptSerializer serializer = new JavaScriptSerializer(); serializer.RecursionLimit = recursionDepth; return serializer.Serialize(obj); } public static List<T> ToListObject<T>(this string obj, int recursionDepth = 100) { JavaScriptSerializer serializer = new JavaScriptSerializer(); serializer.RecursionLimit = recursionDepth; List<T>

Why does IList<T> implement IEnumerable<T> and ICollection<T> while ICollection<T> itself implements IEnumerable<T> [duplicate]

≯℡__Kan透↙ 提交于 2019-12-04 07:40:20
This question already has answers here : Why does List<T> implement IList<T>, ICollection<T> and IEnumerable<T>? (4 answers) Closed 4 years ago . Why is IList defined like this? public interface IList<T> : ICollection<T>, IEnumerable<T>, IEnumerable public interface ICollection<T> : IEnumerable<T>, IEnumerable public interface IEnumerable<T> : IEnumerable Couldn't it just be public interface IList<T> : ICollection<T> So, to test I created these interfaces, just to be sure if that works! public interface IOne { string One(); } public interface ITwo : IOne { string Two(); } public interface

How to compare List<String> to DB Table using LINQ

痴心易碎 提交于 2019-12-04 05:18:23
问题 I have a list<> of phone numbers and I am trying to join that with the corresponding records in the db table and get an order number and a customer ID. Also the list has the whole number as one string and the DB has it broken to area code, prefix, number each as separate fields. I am fairly new to LINQ, so this is a beyond what I currently know. Any suggestions are GREATLY appreciated. var tnbrs = new List<string>(); have tried: var tntable = tnbrs.Cast<DataSet>(); var tntable = tnbrs

Proper way to construct linq queries to achieve fastest performance?

一个人想着一个人 提交于 2019-12-04 02:43:29
Similar question have been asked here but none fits to my need. I made test cases to see which is faster. But I feel my linq code is still slow. How do I construct the linq code for faster performance? Others said using double .Tolist() can cause slower operation, when I test it, it shows that it is faster than any other tests. Test: Preparation --------------------------------------------------------------- return Properties of UserInfo(userinf, true){ UserID = userinf.UserID; FirstName = userinf.user.FirstName; MiddleName = userinf.user.MiddleName; LastName = userinf.user.LastName; LoginID =

How to fill a DataTable with a List(Of t) or convert a List(Of t) to a DataTable?

耗尽温柔 提交于 2019-12-03 14:37:19
问题 I have read many posts on this topic; among them and most recently .NET - Convert Generic Collection to Data Table. Unfortunately, all to no avail. I have a generic collection of structures : Private Structure MyStruct Dim sState as String Dim lValue as Long Dim iLayer as Integer End Structure Dim LOStates As New List(Of MyStruct) I need to fill a DataTable with this list of structures but have no idea how to go about doing this. I am using vb.net in Visual Studio 2008. Any insights will be

Generic List of Generic Interfaces not allowed, any alternative approaches?

青春壹個敷衍的年華 提交于 2019-12-03 08:26:15
问题 I am trying to find the right way to use a Generic List of Generic Interfaces as a variable. Here is an example. It is probably not the best, but hopefully you will get the point: public interface IPrimitive<T> { T Value { get; } } and then in another class, I want to be able to declare a variable that holds a list of objects that implement IPrimitive<T> for arbitrary T . // I know this line will not compile because I do not define T List<IPrimitive<T>> primitives = new List<IPrimitives<T>>;