+92 332 4229 857 99ProjectIdeas@Gmail.com

String Format Function (C#.net)




Represents a string of your specified format.






For Example:

            // Format a ratio as a percentage string.
            // .. You must specify the percentage symbol in the format string.
            // .. It will multiply the value by 100 for you.
            //
            double ratio = 0.73;
            MessageBox.Show(string.Format("{0:0.0%}",ratio));
Output:

                73.0% (Multiplying the 0.73 with 100 to make it 73%)

Another Example:
    
 int day = DateTime.Now.Day;
        int month = DateTime.Now.Month;
        int year = DateTime.Now.Year;
        MessageBox.Show(string.Format("{0} - {0} - {2:yyyy}", day, month, year.ToString()));
Output:

               9 - 8 - 2010 (Printing Currents Day-month-year)

0 comments: