.NET Fiddle

CSharp · Console

/Program.cs

using System;
					
public class Program
{
	public void Main()
    {		 
		Console.WriteLine("hello".CenterString(100));
    }
}

public static class StringExtensions{

    public static string CenterString(this string stringToCenter, int totalLength)
    {
        return stringToCenter.PadLeft(((totalLength - stringToCenter.Length) / 2) 
                            + stringToCenter.Length)
                   .PadRight(totalLength);
    }
}
;