C# Specifying method parameter is not nullable
c#
Solution
You can't, basically. You could perhaps use AOP (such as PostSharp) to do some of it for you via attributes, or code-contracts in 4.0 (allowing compile-time checks); but there is no "non-nullable reference-type" (to compare to the "nullable value-type" etc). Not least: what would fields initialize to? and what would default(...) be?
There have been requests to include something in the langauge to help (essentially doing the null check for you), but it hasn't happened. Something like:
public void Foo (string! myRequiredString nullable) {...}
Problem
How would I go about specifying that a particular parameter of my method is not nullable without putting in my own exceptions within the method itself? Is there something like, ``` public void Foo (String myRequiredString nullable){ } ```