Answers for "StringFormat C#"

13

string format c#

using System;

namespace FormatingTest
{
    class Program
    {
        static void Main(string[] args)
        {
            string s = "Name:{0} {1}, Location:{2}, Age:{3}";
            string msg = string.Format(s, "Ram", "Singh", "Mumbai", 32);
            Console.WriteLine("Format Result: {0}", msg);
            Console.WriteLine("\nPress Enter Key to Exit..");
            Console.ReadLine();
        }
    }
}
Posted by: Guest on April-02-2020
0

StringFormat C#

String.Format("{0,-12}" +    // first argument, left align, 12 character wide column
              "{1,8:yyyy}" + // second argument, right align, 8 character wide column,
                             // formatted as a year
              "{2,12:N0}" +  // third argument, right align, 12 character wide column,
                             // formatted as a number, 0 decimal places
Posted by: Guest on May-26-2021
7

c# string formatting

name = "Bob";
age = 27;
info = $"Your name is {name} and you are {age} years old";
Posted by: Guest on May-20-2020

Browse Popular Code Answers by Language