Suppose text = null OR suppose text = "" String.IsNullOrEmpty(text) ? 0 : int.Parse(text); // it will return zero use the about line to get the desire value to want in place of null or empty