EmerG
EmerG

Reputation: 1046

What will default(interface) return?

I found some code, but I'm not sure what is the purpose of return default of interface?

The interface is implemented by few classes

 public ISocketDevicePart Parent => default(ISocketDevicePart);

 public interface ISocketDevicePart
 {
     ISocketDevicePart Parent { get; }
     IEnumerable<ISocketDevicePart> Childs { get; }
     IXYOffset Offset { get; set; }
 }

I'm not sure about result. Should it return null always?

Upvotes: 4

Views: 100

Answers (1)

Patrick Hofman
Patrick Hofman

Reputation: 156968

Yes, the default of an interface-typed variable is null (it is treated as a reference type).

For completeness, you can view the entire default() list in the documentation.

Upvotes: 8

Related Questions