In C ++, we usually see and write code, for example,
Sample sample=new Sample();
if ( sample == NULL )
{
std::cout<<"Memory allocation failed" << std::endl;
}
But in C #, I rarely see this: (at least I never saw this)
Sample sample = new Sample();
if ( sample == null )
{
Console.WriteLine("Memory allocation failed\n");
}
So in C # we rarely check if a newfails or not. Why is this so? Is this related to "In C #, the new will never work"? Is there such a thing in C # that newnever fails?
If this fails, then why is such a “check” so rare in C #? I am not talking about OutOfMemoryException, that is, after all exceptions, not "check". I am talking about coding style.
source
share