Discussion Forum : generics

Why does C# forbid generic attribute types?
This causes a compile-time exception: public sealed class ValidatesAttribute<T> : Attribute {  }  [Validates<string>] p ... View Detail
 Upvotes: 0   Answers: 0
Cast Object to Generic List
I have 3 generict type list. List<Contact> = new List<Contact>(); List<Address> = new List<Address>(); List<Document> = ... View Detail
 Upvotes: 0   Answers: 0
Using List<T> in C# (Generics)
That's a pretty elementary question, but I have never delved into generics before and I found myself in the need to use ... View Detail
 Upvotes: 0   Answers: 0
What is cool about generics, why use them?
I thought I'd offer this softball to whomever would like to hit it out of the park. What are generics, what are the adva ... View Detail
 Upvotes: 0   Answers: 0
Generics - where T is a number?
I'm trying to figure a way to create a generic class for number types only, for doing some calculations. Is there a com ... View Detail
 Upvotes: 0   Answers: 0
Convert List<T> to object[]
I am looking for a one liner that transforms List<T> into object[]. It's one liner, so I am not interested in solutions ... View Detail
 Upvotes: 0   Answers: 0
Help with C# generics error - The type 'T' must be a non-nullable value type
I'm new to C# and don't understand why the following code doesn't work. public static Nullable<T> CoalesceMax<T>(Nullab ... View Detail
 Upvotes: 0   Answers: 0
Generic TryParse
I am trying to create a generic extension that uses 'TryParse' to check if a string is a given type: public static bool ... View Detail
 Upvotes: 0   Answers: 0
How to cast List<object> to List<SomethingElse>
How can i cast a List<object> to List<SomethingElse>? (where SomethingElse is known to descend from object) Bonus Ch ... View Detail
 Upvotes: 0   Answers: 0
Elegant way to combine multiple collections of elements?
Say I have an arbitrary number of collections, each containing objects of the same type (for example, List<int> foo and ... View Detail
 Upvotes: 0   Answers: 0
C# Casting a List<ObjBase> as List<Obj>
Why can I not cast a List<ObjBase> as List<Obj>? Why does the following not work: internal class ObjBase { }  internal  ... View Detail
 Upvotes: 0   Answers: 0
Generic Way to Check If Entity Exists In Entity Framework?
Similar to Best way to check if object exists in Entity Framework? I'm looking for a generic way to check for an entity ... View Detail
 Upvotes: 0   Answers: 0
How to call generic method with a given Type object?
I want to call my generic method with a given type object. void Foo(Type t) {   MyGenericMethod<t>(); }  obviously doe ... View Detail
 Upvotes: 0   Answers: 0
Cannot implicitly convert type 'Int' to 'T'
I can call Get<int>(Stat); or Get<string>(Name); But when compiling I get: Cannot implicitly convert type 'int' to ... View Detail
 Upvotes: 0   Answers: 0
Is there a generic constructor with parameter constraint in C#?
In C# you can put a constraint on a generic method like: public class A {   public static void Method<T> (T a) where T  ... View Detail
 Upvotes: 0   Answers: 0
Case insensitive access for generic dictionary
I have an application that use managed dlls. One of those dlls return a generic dictionary: Dictionary<string, int> M ... View Detail
 Upvotes: 0   Answers: 0
Can I Create a Dictionary of Generic Types?
I'd like to create a Dictionary object, with string Keys, holding values which are of a generic type. I imagine that it ... View Detail
 Upvotes: 0   Answers: 0
How can I convert IEnumerable<T> to List<T> in C#?
I am using LINQ to query a generic dictionary and then use the result as the datasource for my ListView (WebForms). Sim ... View Detail
 Upvotes: 0   Answers: 0
Implement an Interface with Generic Methods
I'm drawing a blank on this one and can't seem to find any previous example that I wrote. I'm trying to implement a gene ... View Detail
 Upvotes: 0   Answers: 0
Null or default comparison of generic argument in C#
I have a generic method defined like this: public void MyMethod<T>(T myArgument)  The first thing I want to do is chec ... View Detail
 Upvotes: 0   Answers: 0
c# compare two generic values
Possible Duplicate: Can’t operator == be applied to generic types in C#? I've coded something like this: pub ... View Detail
 Upvotes: 0   Answers: 0
Create List<int> with values at compile time
It is possible to create an array at compile time like; int[] myValues = new int[] { 1, 2, 3 } ;  But I would like to ... View Detail
 Upvotes: 0   Answers: 0
Generic list FindAll() vs. foreach
I'm looking through a generic list to find items based on a certain parameter. In General, what would be the best and f ... View Detail
 Upvotes: 0   Answers: 0
Console.WriteLine and generic List
I frequently find myself writing code like this: List<int> list = new List<int> { 1, 3, 5 }; foreach (int i in list) {  ... View Detail
 Upvotes: 0   Answers: 0
Generic method with multiple constraints
I have a generic method which has two generic parameters. I tried to compile the code below but it doesn't work. Is it a ... View Detail
 Upvotes: 0   Answers: 0

Quick Links

E-Magazines

@

Total Followers
Study Group Created
Study Group Joined
Following Teacher
Following Organization
Blog Articles Added
Questions Asked
Questions Answered
Jobs Posted
Total Members in Group
Questions asked by members
Tasks added in this Group

Please wait..

Ok

Login to Open ESchool OR Create your account    Login   SignUp