Northrop Grumman Interview Question

2 - in C#, can you tell whether whatever the user has input is a string or integer?

Interview Answers

Anonymous

Feb 23, 2012

bool isInt(string userInput) { int i; return Int32.TryParse(userInput, out &i); }

Anonymous

Feb 7, 2014

if it's ASP.NET - regardless of whether the code-behind is C# or VB, a will reject non-integers also IsInt posted above will work (but take out the ampersand, that's what the 'out' is for). as #1 mentioned, this works too: return System.Text.Regex.IsMatch(userInput, "^\d+$", RegexOptions.CultureInvariant);

Anonymous

Jun 21, 2010

2- no. there is no method like that. you have to make your own. I did that with regex