I have this: class Program { static void Main(string[] args) { var result = new Result<int, bool> { success = true, Data = 88 }; var result2 = new Result<string, bool> { success = true, Data = "Niels" }; Console.WriteLine(result2.suc
For several HTML forms, I want to configure inputs and deal with their values. My types have the following structure (you may copy it to TypeScript Playground http://www.typescriptlang.org/play to see it in action): interface InputConfig { readonly i
I was reading concept of type erasure in generics. While executing the below piece of code I got confused. public class CollectionsWild { void Test(Collection<?> t){ System.out.println("Collection"); } void Test(List<Integer> t){ Sys
Sorry if title of question is a little bit vague. Suppose we have the following code class ReportManager<T> where T : IPrint { public void MakePaperCopy(T t) { //... t.Print(); //... } } public interface IPrint { void Print(); } It can be easily rem
I am trying some weird generics in java. In the following code, the override on foo works, but the override on bar doesn't. I don't understand why. Note that the only difference between the 2 overrides is in the constraints on MB. When overriding foo
I have a generic struct which accepts any type, and a function: struct Test<T> { func makeSomething() -> T? { print("Default implementation") return nil } } I also have a protocol which contains a static method which returns an instance
I have tried to write a generic method for the below mentioned code snippet.But it gives error on the OrderBy clause ? Could you tell me why ? var cache = RedisConnectorHelper.Connection.GetDatabase(); var values = JsonConvert.DeserializeObject<List<
I have a test class that tries to reach to google with a NSURLConnection. If I try to make it generic, the NSURLConnectionDataDelegate methods are never called. class Remote<T: NSObject>: NSObject, NSURLConnectionDelegate, NSURLConnectionDataDelegat
I would like to have a variable number of arguments in my S4 generic myMethod such that these are both valid: myMethod(100) myMethod(100, 200) Here is my attempt at a definition: setGeneric( "myMethod", function(x) { standardGeneric("myMeth
I am new to java generics my question is : public static < E > void printArray( E[] inputArray ) In the above statement when the return type of function is void then why we have used E before void? Why this syntax is valid ? As per theory a method c
I'm using the MSDN examples for variance in delegate. But the following code is giving me a compilation error. Based on my understanding, it should accept the First as an argument. What am I doing wrong? The code sample. SampleGenericDelegate<Second,
I am writing a networked application. My model objects contain delegates that are called when a value changes. I have network objects that use the delegates to send the changed value over the network: Model: public class Person : AbstractModel { publ
I'm reading through the generics section currently and have come across a section titled "Conversion Type Constraints". I couldn't get my head around Jon's explanation so I typed the term into Google to find no results that use this exact phrase
I have found some strange code, where I said "This is never called, because it would throw a class cast Exception". Well the code gets called and its working. Can anybody explain me: Why is this working? The method getZipList() is defined to ret
What is the concept behind the Generic extend that why is it not allowed to modify the list; why does it throw a compile time error when I add a string to list , since String extends Object and should be legal. If this gives compilation error , then
A student that I am tutoring is taking a web development class that uses a Dietel book on Java, which contains this curious bit of code involving Generics: class StackComposition <T> { private List<T> stackList; public StackComposition() { sta
Is it possible in C# to create a type at runtime that inherits from a generic class where the template parameter for the base class is the current class being constructed? This will compile fine: // I have this class: public class OtherClass<T> wher
I suspect the answer is no, but I want to know if it is possible to do something like this: public class MyGenericClass<TSomeClass> { public void MyGenericMethod<TSomeInterface>() // This doesn't compile. where TSomeClass : TSomeInterface { //
In my GWT app I have a datatype (intended for building and tracking hierarchies of like objects) that extends a superclass, which in turn extends another, abstract superclass. There is a generic parameter declared in the abstract class which is then
Here's a class public class Repository<T> { T GetSingle(Expression<Func<T, bool>> condition); } And then in another class that takes a generic type argument I have something like: repo = new Repository<TEntity>(); repo.GetSingle(x=
I have multiple classes (B, C and D) that are subclasses of class A. I need to make a List/Array containing B, C and D and create Objects based on whatever element I pull from the List/Array. In AS3 I would do something like this: var classes:Array =
I have a class called Order which has properties such as OrderId, OrderDate, Quantity, and Total. I have a list of this Order class: List<Order> objListOrder = new List<Order>(); GetOrderList(objListOrder); // fill list of orders Now I want to
I am trying to figure out a way to leverage generics so I can make the property Value be an actual type that initialized (not sure if this is the correct way of saying it) when my collection class is created. I would like to have the syntax be someth
I'm using LINQtoSQL and I want to return a list of matching records for a CSV contains a list of IDs to match. The following code is my starting point, having turned a CSV string in a string array, then into a generic list (which I thought LINQ would
Is the following at all possible in c#? I have the following but the last line won't compile, am i missing something? public static void BuildGeneric<T>(List<T> l) { l = new List<T>(); var anything = new object(); l.Add(anything); } &quo
I have an ArrayList of objects that I need to sort in two different fashions, depending on the situation. I followed this example: http://codebetter.com/blogs/david.hayden/archive/2005/03/06/56584.aspx on how to create a PersonComparer by overloading
I have the following extension method to add the elements in one collection to another collection: public static void AddRange<T>(this ICollection<T> collection, IEnumerable<T> list) { foreach (var item in list) { collection.Add(item); }
I have an application where client and server share types, and interoperability is not one of our concerns. I am planning to have a single repository for all web enabled objects, and i was thinking of a generic interface for my exposed service. somet
In this simplified example I have a generic class, and a method that returns a Map regardless of the type parameter. Why does the compiler wipe out the types on the map when I don't specify a type on the containing class? import java.util.Map; public
Is there a way to convert a List(of Object) to a List(of String) in c# or vb.net without iterating through all the items? (Behind the scenes iteration is fine - I just want concise code) Update: The best way is probably just to do a new select myList