Get the 2-digit string representation of an integer in [1,99] - CSharp Language Basics

CSharp examples for Language Basics:int

Description

Get the 2-digit string representation of an integer in [1,99]

Demo Code


using System.Text;
using System.Linq;
using System.Collections.Generic;
using System;//from  w w w  . j a v a  2 s.  c o m

public class Main{
        /// <summary>
        /// Get the 2-digit string representation of an integer in [1,99] 
        /// </summary>
        /// <param name="num"></param>
        /// <returns></returns>
        public static string GetTwoDigitString(int num)
        {
            if (num < 1 || num >= 100)
                return null;

            if (num < 10)
                return "0" + num.ToString();
            else
                return num.ToString();
        }
}

Related Tutorials