Search
 
SCRIPT & CODE EXAMPLE
 

CSHARP

c# collection of generic classes

public abstract class MyClass
{
    public abstract Type Type { get; }
}

public class MyClass<T> : MyClass
{
    public override Type Type
    {
        get { return typeof(T); }
    }

    public T Value { get; set; }
}

// VERY basic illustration of how you might construct a collection
// of MyClass<T> objects.
public class MyClassCollection
{
    private Dictionary<Type, MyClass> _dictionary;

    public MyClassCollection()
    {
        _dictionary = new Dictionary<Type, MyClass>();
    }

    public void Put<T>(MyClass<T> item)
    {
        _dictionary[typeof(T)] = item;
    }

    public MyClass<T> Get<T>()
    {
        return _dictionary[typeof(T)] as MyClass<T>;
    }
}
Comment

PREVIOUS NEXT
Code Example
Csharp :: c# exit foreach 
Csharp :: unity read console log 
Csharp :: what are delegates and how to use them c# 
Csharp :: add to ienumerable 
Csharp :: what is int.parse in c# 
Csharp :: c# sequential struct with fixed array size 
Csharp :: C# date type no time 
Csharp :: error cs1585 unity 
Csharp :: ioptions mock c# unittest 
Csharp :: check .net installing 
Csharp :: scaffolding in vs22 asp.net 6 
Csharp :: c# webbrowser upload file 
Csharp :: c# get program version 
Csharp :: txt.att.net not working 2021 
:: scale min max to 0 1 
Csharp :: gcm_sender_id convert text 
Csharp :: ef6 export update 
Csharp :: enzymes chemical factory 
:: c# get innermost exception 
Csharp :: [Package Manager Window] Error while fetching labels: User is not logged in or user status invalid. UnityEngine.GUIUtility:ProcessEvent (int,intptr,bool&) 
Csharp :: is list sequential C# 
Csharp :: c sharp right rotation 
Csharp :: how to make dissapear an object in unity 
Csharp :: Get cell value with formatting openxml 
Csharp :: C# Move Camera Over Terrain Using Touch Input In Unity 3D 
Csharp :: binary search between two indexes 
Csharp :: lambda not null c# 
Csharp :: WPF combobox filter as you type 
Csharp :: c# alert message 
Csharp :: c# remove exit icon 
ADD CONTENT
Topic
Content
Source link
Name
7+2 =