我不清楚你在问什么,但我认为你只想创建自己的泛型来包装泛型 SortedDictionary。
using System.Collections.Generic;
namespace Controller.Framework
{
class CSortedDictionary<CustomDataType1, CustomDataType2>
{
private SortedDictionary<CustomDataType1, CustomDataType2> m_dictionary;
// other methods which work on m_dictionary;
}
}
// Create custom dictionary...
var custom_dictionary = new CSortedDictionary<int, List<string>>();
或者像谢尔盖所说的那样继承
using System.Collections.Generic;
namespace Controller.Framework
{
class CSortedDictionary<CustomDataType1, CustomDataType2>: SortedDictionary<CustomDataType1, CustomDataType2>
{
// other methods which work on m_dictionary;
}
}
// Create custom dictionary...
var custom_dictionary = new CSortedDictionary<int, List<string>>();
也许您想考虑为SortedDictionary 提供一种扩展方法,尽管这不受欢迎。
using System.Collections.Generic;
namespace Controller.Framework
{
public static class CSortedDictionaryExtensions
{
public static DoSomething<CustomDataType1, CustomDataType2>(this SortedDictionary<CustomDataType1, CustomDataType2> dictionary){
dictionary.SomeMethod();
}
// other methods which work on m_dictionary;
}
}
// Create custom dictionary...
var dictionary = new SortedDictionary<int, List<string>>();
dictionary.DoSomething();
[编写但未编译]