Given a string format and a number, returns its string representation. - CSharp System

CSharp examples for System:String Number

Description

Given a string format and a number, returns its string representation.

Demo Code


using System.Collections.Generic;

public class Main{
        /// <summary>
        /// Given a string format and a number, returns its string representation.
        /// It's better to use this method than just number.ToString() since,
        /// in the long term, it does not generate string garbage.
        /// </summary>
        /// <param name="format"></param>
        /// <param name="number"></param>
        /// <returns></returns>
        public static string Format(string format, int number) {
            Index ui = new Index(format, number);

            if (!stringTable.ContainsKey(ui))
                stringTable[ui] = ui.GetString();

            return stringTable[ui];
        }/*from  w  w w .j  a  va2s. co m*/
}

Related Tutorials