Saving from List to txt

There’s a handy little method File.WriteAllLines — no need to open a StreamWriter yourself: In .net 4: File.WriteAllLines(speichern, ausgabeListe); In .net 3.5: File.WriteAllLines(speichern, ausgabeListe.ToArray()); Likewise, you could replace your reading logic with File.ReadAllLines, which returns an array of strings (use ToList() on that if you want a List<string>). So, in fact, your complete code could … Read more

How to free a generic TList?

Executive summary MyList.Free is sufficient. Detailed answer The TList<T> generic container owns its contents. When you free the container, the contents are also disposed of. Now, if T is an unmanaged reference, either a pointer or a class, then the list owns the reference. It does not own that which the reference refers to. So … Read more

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

public interface IPrimitive { } public interface IPrimitive<T> : IPrimitive { T Value { get; } } public class Star : IPrimitive<T> //must declare T here { } Then you should be able to have List<IPrimitive> primitives = new List<IPrimitive>; primitives.Add(new Star()); // Assuming Star implements IPrimitive primitives.Add(new Sun()); // Assuming Sun implements IPrimitive

Jackson JSON + Java Generics get LinkedHashMap

The following works and as per StaxMan’s advice no longer uses the deprecated static collectionType() method. public class SoApp { /** * @param args * @throws Exception */ public static void main(String[] args) throws Exception { System.out.println(“Hello World!”); String s = “[{\”user\”:\”TestCity\”,\”role\”:\”TestCountry\”},{\”user\”:\”TestCity\”,\”role\”:\”TestCountry\”}]”; StringReader sr = new StringReader(“{\”user\”:\”TestCity\”,\”role\”:\”TestCountry\”}”); //UserRole user = mapper.readValue(sr, UserRole.class); mapJsonToObjectList(s,UserRole.class); } protected … Read more

Generic list of generic objects

Yes, generics is a good choice. The key to achieving type-safety (and being identify the type with the Type property is to add an abstraction between the list and Field<T> class. Have Field<T> implement the interface IField. This interface doesn’t need any members. Then declare your list as being List<IField>. That way you constrain the … Read more

Editing an item in a list

After adding an item to a list, you can replace it by writing list[someIndex] = new MyClass(); You can modify an existing item in the list by writing list[someIndex].SomeProperty = someValue; EDIT: You can write var index = list.FindIndex(c => c.Number == someTextBox.Text); list[index] = new SomeClass(…);

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