Create and use a String Object - CSharp Language Basics

CSharp examples for Language Basics:string

Description

Create and use a String Object

Demo Code

using System;/*from  w ww .  j a v  a 2s  . c  o  m*/
class Program
{
    static void Main(string[] args)
    {
        string fname, lname;
        fname = "Jesse";
        lname = "Pinkman";
        string fullname = fname + lname;
        Console.WriteLine("Full Name: {0}", fullname);

        char[] letters = new char[] { 'a','v','c' }; 
        string greetings = new string(letters);
        Console.WriteLine("Greetings: {0}", greetings);

        string message = String.Join(" ", letters);
        Console.WriteLine("Message: {0}", message);
        DateTime waiting = new DateTime(2012, 10, 10, 17, 58, 1);
        string chat = String.Format("Message sent at {0:t} on {0:D}", waiting);
        Console.WriteLine("Message: {0}", chat);
    }
}

Result


Related Tutorials