Can I create anonymous implementations of the interface, similar to the way
delegate() {
Something in the lines
new IInterface() {
Situations in which I see them useful are to specify method parameters that are interface types, and there is too much code when creating a class type.
For example, consider the following:
public void RunTest()
{
Cleanup(delegate() { return "hello from anonymous type"; });
}
private void Cleanup(GetString obj)
{
Console.WriteLine("str from delegate " + obj());
}
delegate string GetString();
how will this be achieved if the Cleanup method had an interface as a parameter in the above code without writing a class definition? (I think Java allows expressions like new Interface () ...)
source
share