java.lang.IndexOutOfBoundsException: Source does not fit in dest

Capacity does not equal size. The size parameter that you are passing in simply allocates enough memory for the size. It does not actually define elements. It’s actually kind of a silly requirement of Collections.copy, but it is one nonetheless. The key part from the Collections.copy JavaDocs: The destination list must be at least as … Read more

C# Iterate through NameValueCollection

You can flatten the collection with Linq, but it’s still a foreach loop but now more implicit. var items = nvc.AllKeys.SelectMany(nvc.GetValues, (k, v) => new {key = k, value = v}); foreach (var item in items) Console.WriteLine(“{0} {1}”, item.key, item.value); The first line, converts the nested collection to a (non-nested) collection of anonymous objects with … Read more

Collection was modified; enumeration operation may not execute in ArrayList [duplicate]

You are removing the item during a foreach, yes? Simply, you can’t. There are a few common options here: use List<T> and RemoveAll with a predicate iterate backwards by index, removing matching items for(int i = list.Count – 1; i >= 0; i–) { if({some test}) list.RemoveAt(i); } use foreach, and put matching items into … Read more

.NET – Convert Generic Collection to DataTable

Then presumably you’ll need to lift them to the non-nullable form, using Nullable.GetUnderlyingType, and perhaps change a few null values to DbNull.Value… Change the assignment to be: row[prop.Name] = prop.GetValue(item) ?? DBNull.Value; and when adding the columns to be: table.Columns.Add(prop.Name, Nullable.GetUnderlyingType( prop.PropertyType) ?? prop.PropertyType); And it works. (?? is the null-coalescing operator; it uses the … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)