Format a C# String

In this article we will discuss about how to format the string in C#.
  • 2637

The string.Format method is used to create formatted strings and concatenate multiple strings representing multiple objects. The Format method automatically converts any passed object into a string.

For example, the following code uses an integer, a floating number and string values and formats them into a string using the Format method.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication4
    class Program
        static void Main(string[] args)
          int val = 7;
          string name = "Mr. John";
          float num = 45.06f;
          string str = String.Format("Days Left : {0}. Current DataTime: {1:u}. \n String: {2},Float: {3}", val, DateTime.Now, name,num);

Further Readings
You may also want to read these related articles.

Ask Your Question 

Got a programming related question? You may want to post your question here


More Articles

© 2020 DotNetHeaven. All rights reserved.