Click here to Skip to main content
15,917,456 members
Home / Discussions / C#
   

C#

 
AnswerRe: prevent form resizing Pin
Nuri Ismail20-Jan-10 3:24
Nuri Ismail20-Jan-10 3:24 
AnswerRe: prevent form resizing Pin
Rob Philpott20-Jan-10 5:12
Rob Philpott20-Jan-10 5:12 
Questiontwo titles on title bar Pin
Jassim Rahma20-Jan-10 2:46
Jassim Rahma20-Jan-10 2:46 
AnswerRe: two titles on title bar Pin
Harvey Saayman20-Jan-10 19:45
Harvey Saayman20-Jan-10 19:45 
GeneralRe: two titles on title bar Pin
Jassim Rahma21-Jan-10 12:10
Jassim Rahma21-Jan-10 12:10 
QuestionConvert string to nullable int Pin
John_1020-Jan-10 2:35
John_1020-Jan-10 2:35 
AnswerRe: Convert string to nullable int Pin
EliottA20-Jan-10 2:43
EliottA20-Jan-10 2:43 
AnswerRe: Convert string to nullable int [modified] Pin
Keith Barrow20-Jan-10 2:51
professionalKeith Barrow20-Jan-10 2:51 
First, I'd avoid nulls unless absolutly neccesary, the can cause all sorts of problems if they are not coded against.

The exact code you need depends upon your desired "failure mode" (see comment in block) but here is an answer:

static int? Convert (string value)
 {
     if (string.IsNullOrEmpty(value))
         return null;

     int returnedInt;
     if (int.TryParse(value, out returnedInt))
         return returnedInt;

     // I've asssumed that you want null if the value is unparsable
     // You might want to throw an argument exception instead here.
     return null;
 }


also IMO nullint is a shoud be renamed as it has both "null" and "int" in it, as well as not being very descriptive.


[Edit]

Nuri Ismails post (below) achieves the same as the above, but is more compact, so I'd use that in preference.

CCC solved so far: 2 (including a Hard One!)
37!?!! - Randall, Clerks

modified on Wednesday, January 20, 2010 9:00 AM

AnswerRe: Convert string to nullable int PinPopular
Nuri Ismail20-Jan-10 2:52
Nuri Ismail20-Jan-10 2:52 
QuestionWeb service to receive a pdf file as MIME attachment Pin
Gktony20-Jan-10 2:12
Gktony20-Jan-10 2:12 
QuestionConnections options in C# Pin
vinothkumar_Dhakshinamoorthy20-Jan-10 2:04
vinothkumar_Dhakshinamoorthy20-Jan-10 2:04 
AnswerRe: Connections options in C# Pin
Covean20-Jan-10 2:49
Covean20-Jan-10 2:49 
GeneralRe: Connections options in C# Pin
vinothkumar_Dhakshinamoorthy20-Jan-10 4:21
vinothkumar_Dhakshinamoorthy20-Jan-10 4:21 
Questionadding an icon to desktop in setup and deployment project Pin
samy10020-Jan-10 0:59
samy10020-Jan-10 0:59 
AnswerRe: adding an icon to desktop in setup and deployment project Pin
daxfrost20-Jan-10 1:43
daxfrost20-Jan-10 1:43 
AnswerRe: adding an icon to desktop in setup and deployment project Pin
Nuri Ismail20-Jan-10 1:52
Nuri Ismail20-Jan-10 1:52 
QuestionC# and LISP comparison Pin
gamer112720-Jan-10 0:59
gamer112720-Jan-10 0:59 
AnswerRe: C# and LISP comparison Pin
SeMartens20-Jan-10 1:16
SeMartens20-Jan-10 1:16 
QuestionSetForegroundWindow Pin
sucil20-Jan-10 0:24
sucil20-Jan-10 0:24 
AnswerRe: SetForegroundWindow Pin
daxfrost20-Jan-10 0:31
daxfrost20-Jan-10 0:31 
QuestionExport datagrid to excel or csv Pin
codenoobie19-Jan-10 23:55
codenoobie19-Jan-10 23:55 
AnswerRe: Export datagrid to excel or csv Pin
sanforjackass20-Jan-10 1:01
sanforjackass20-Jan-10 1:01 
GeneralRe: Export datagrid to excel or csv Pin
codenoobie20-Jan-10 1:24
codenoobie20-Jan-10 1:24 
QuestionXmlSerializer - usage within constructors Pin
lukeer19-Jan-10 23:07
lukeer19-Jan-10 23:07 
AnswerRe: XmlSerializer - usage within constructors Pin
Covean19-Jan-10 23:51
Covean19-Jan-10 23:51 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.