Home » ASP.NET » C# string 0008

C# string 0008

C# string object 0008, there is a friend in need of reference.


note:.NET", "C#", "String" in

, and "string" in lowercase

  1. if you use string, the compiler will compile it into String, so if you use String directly, you can make the compiler do a little bit less work. If you use c#, it is recommended to use string, which is more in line with the standard.

  2. string is a keyword, String is not, that is, string cannot be used as a class, structure, enumeration, field, variable, method, property name, and String can.


using System;
namespace StringApplication
{

class Program
{

static void Main (string[] args)
{
string, fname, lname;
Fname = , Henry, , lname = , Tien, ;
string fullname = fname + lname;
Console.WriteLine (, Full, Name:{0}, , fname);
//by using string constructor
char[], letters = {'H', 'e', 'l', 'l', 'o'};
string greeting = new string (letters);
Console.WriteLine (, Greeting:{0}, , greeting);
// method returning string
string[], sarray = {, Hello, , , From, , , Henry, };
string message = String.Join (), , sarray);
Console.WriteLine (, Message:, , message);
//, formatting, method, to, convert, a, value
DateTime, waiting = new, DateTime (2016, 04, 21, 16, 40, 1);
string chat = String.Format (, Message, sent, at, {0:t}, on, {0:D}, , waiting);
Console.WriteLine (, Message, {0}, , chat);
Console.ReadKey ();
}
}
}

output:

Full Name:Henry

Greeting:Hello

Message:

Message, Message, sent, at, 4:40, PM, on, Thursday, April 21, 2016


Latest