The following doesn't work:
public string foo()
{
using (Random myRandomChoice = new Random())
{
return myRandomChoice.Next(10).ToString();
}
}
The following is errors:
public string foo()
{
Random myRandomChoice = new Random();
return myRandomChoice.Next(10).ToString();
}
The error message for the first foo
is concerning Random
not being implicitly convertable to System.IDisposable
.
Is this a deliberate ploy withing the syntax of the language so you only use using
in specific circumstances e.g when dealing with database connections? or can I explicitly convert Random
to type IDisposable
so that the initial foo
works?
Is there a list available of types that would be better declared with using
?