If I have an Interface that I later implement in a class, when I implement it in a List, can T be the name of the interface?
Interface:
interface IItem
{
int id { get; set; }
string name { get; set; }
}
Serialized class:
[System.Seriazable]
public class Martillo : IItem
{
public int damage { get; set; }
// Implement interface IItem
int id { get; set; }
string name { get; set; }
}
Dictionary method:
public Dictionary<string, List<T> addDictionary<T>( T _item, string _index){
Dictionary<string, List<T> dic = new Dictionary<string, List<T>();
dic.Add(_index, List<_item>);
return dic;
}
The case in point is that I have a Dictionary that houses a list, when I want to extract the list from the dictionary it becomes an object and it does not let me use the methods of List < & gt ;. I can castear the object that returns to me from its interface (already in this dictionary I have several list of with the same interface).
Can I cast him like that?
List<IItem> martillo = dictionary["Martillo"] as List<IItem>;
Or do I have to do it by force like this?
List<Martillo> martillo = dictionary["Martillo"] as List<Martillo>;