Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I convert int? into int

Tags:

c#

linq-to-sql

I've create a SPROC that saves an object and returns the id of the new object saved. Now, I'd like to return an int not an int?

public int Save(Contact contact)
{
  int? id;
  context.Save_And_SendBackID(contact.FirstName, contact.LastName, ref id);
  //How do I return an int instead of an int?
}

Thanks for helping

like image 621
Richard77 Avatar asked Jun 14 '10 19:06

Richard77


1 Answers

return id.Value; // If you are sure "id" will never be null

or

return id ?? 0; // Returns 0 if id is null
like image 185
Philippe Leybaert Avatar answered Sep 21 '22 20:09

Philippe Leybaert