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

Popular posts from this blog

asp.net - repeatedly call AddImageUrl(url) to assemble pdf document -

java - Android recognize cell phone with keyboard or not? -

iphone - How would you achieve a LED Scrolling effect? -