compiler construction - C#: Declare that a function will never return null? -
background: there developer principle "should function return null or throw exception if requested item not exist?" wouldn't discuss here. decided throw exception cases have return value , value wouldn't exist in cases of (programmatically or logically) invalid request.
and question: can mark function compiler knows never return null , warn checks if return value null?
you can using code contracts
.
example :
public string method1() { contract.ensures(contract.result<string>() != null); // }
Comments
Post a Comment