c# tolist if null code example

Example 1: c# is number even

/*
 * C# Program to Check whether the Entered Number is Even or Odd
 */
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
 
namespace check1
{
    class Program
    {
        static void Main(string[] args)
        {
            int i;
            Console.Write("Enter a Number : ");
            i = int.Parse(Console.ReadLine());
            if (i % 2 == 0)
            {
                Console.Write("Entered Number is an Even Number");
                Console.Read();
            }
            else
            {
                Console.Write("Entered Number is an Odd Number");
                Console.Read();
            }
        }
    }
}

Example 2: c# check if int is null

// When trying to check if your int is null or i.e. 'not set',
// you will get the following error:

// The result of the expression is always 'false'
// since a value of type 'int' is never equal to 'null' of type 'int?'

// You can however bypass this by converting your int to string:
int myInt = null;
// This Method will return a bool;
bool isNullInt = string.IsNullOrEmpty(myInt.ToString());
// isNullInt will be in this case true