Your code example is quite confusing and does not compile. However, to answer your question about the List<T>.this
syntax:
This is called explicit interface implementation. You use this to implement an interface but hide it from the public signature of the class. Here is a small example:
public class Foo : IDisposable {
public void Dispose() {
}
}
public class Bar : IDisposable {
public void Close() {
}
void IDisposable.Dispose() {
Close();
}
}
Both classes implement IDisposable
but to dispose a Bar
you will have to call Close
. You can also cast it to IDisposable
and then call Dispose
.
var foo = new Foo();
foo.Dispose();
var bar = new Bar();
bar.Close();
((IDisposable) bar).Dispose();
For classes Foo
and Bar
it may not be important if the cleanup method is called Dispose
or Close
but for a File
class you may prefer to Close
it instead of Dispose
it. Other uses is to hide an interface you have to implement to participate in an interaction between objects but you don't want to be visible to consumers of your class. Or you can use it to work around implementing multiple interfaces with conflicting methods.
You can read about explicit interface implementation on MSDN.