Register
Thursday, September 09, 2010
 
 DBAs And ProgrammersBlog
  
News! Minimize
   
 
 Print   
 
Misc Blog Stuff Minimize
   
 
 Print   
 
The Reluctant DBA Minimize
 
 
 
 Print   
 
Reluctant DBA Minimize
   
 
  
 
Reluctant DBA Minimize
   
 
  
 
The Reluctant DBA Minimize
 
Jan7

Written by:CarpDeus
1/7/2009 10:38 AM 

The short answer, of course, is when it's a short, but that's not why the following code throws an error:

(CanContactGeneral == string.Empty ? 0 : Convert.ToInt16(CanContactGeneral))

Here we are evaluating a string to determine whether to use a number or a 0. And the error that gets thrown is Type of conditional expression cannot be determined because 'int' and 'short' implicitly convert to one another. Which makes perfect sense, I was being lazy and should have handled this better, but I was asking the compiler to turn this expression into either an int or a short but not giving it any guidance. So I could change the 0 to Convert.ToInt16(0), but then I realized I was using this in a string.Format, so I just eliminated the Convert statement and all was well.

Tags:

Your name:
Your email:
(Optional) Email used only to show Gravatar.
Your website:
Title:
Comment:
Security Code
Enter the code shown above in the box below
Add Comment  Cancel 
 
 
  
 
Privacy Statement | Terms Of Use Copyright 2001-2008 by ReluctantDBA.com