Hello =)
I'm a classic newbie...
i can compile my program, but get an invalidcast excpetion when running the programm
what's wrong with my code. i don't not what to seach for :(
This is my code (.net 3.5)
class Element{
private int i;
public int I { get { return i; } set { i = value; } }
private string s;
public string S { get { return s; } set { s = value; } }
public Element(string _s, int _i) {
this.s = _s;
this.i = _i;
}
}
class myDict : Dictionary<string, Element> {
public void afunction() {
}
}
class Program {
static void Main(string[] args) {
myDict myDict = new myDict();
myDict.Add("a", new Element("x", 23));
myDict.Add("b", new Element("y", 48));
var sortedDict = ((from entry in myDict orderby entry.Key descending select entry).Take(10));
myDict = (myDict)sortedDict.ToDictionary(v => v.Key, v => v.Value);
foreach (KeyValuePair<string, Element> kvp in myDict) {
System.Console.WriteLine("-> " +kvp.Key + " " + kvp.Value);
}
Console.ReadLine();
}
}
thanks! michael :)