Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What will default(interface) return?

Tags:

c#

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?

like image 368
EmerG Avatar asked Mar 04 '23 18:03

EmerG


1 Answers

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.

like image 195
Patrick Hofman Avatar answered Mar 12 '23 17:03

Patrick Hofman