Generic without a specific type

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

Generic TypeScript interface with mixed member types

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

Type erasure in the confusion of generics

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

Do we really need a generic class with type constraint?

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

Replacement error in the java method with weird generics

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

The generic method gives an error

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<

NSURLConnection delegate methods not called in generic class

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

Java Generics: explanation of the syntax

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

Generic contravariance delegate compiler error

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,

Generic case to react to changes in model value

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

Generic concept of stretches and super

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

How to use an expression with a generic

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=

List of classes in Java

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 =

How to sort a list & lt; T & gt; by a property in the object

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

LINQ-to-SQL: search against a CSV file

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

Generic lists C #

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

wcf exposing generics

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

Why this generic Java code will not compile?

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

Convert the list (of the object) to List (of the string)

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