How to create String object in C #
In this article, the editor introduces in detail "how to create String objects in C#". The content is detailed, the steps are clear, and the details are handled properly. I hope this article "how to create String objects in C#" can help you solve your doubts.
Create a String object
You can create a string object using one of the following methods:
By assigning a string to the String variable
By using the String class constructor
By using the string concatenation operator (+)
By retrieving a property or calling a method that returns a string
Convert a value or object to its string representation by formatting
The following example demonstrates this:
Using System
Namespace StringApplication
{
Class Program
{
Static void Main (string [] args)
{
String / string concatenation
String fname, lname
Fname = "Rowan"
Lname = "Atkinson"
String fullname = fname + lname
Console.WriteLine ("Full Name: {0}", fullname)
/ / by using the string constructor
Char [] letters = {'Haugh,' eBay, 'lumbago.
String greetings = new string (letters)
Console.WriteLine ("Greetings: {0}", greetings)
/ / method returns a string
String [] sarray = {"Hello", "From", "Tutorials", "Point"}
String message = String.Join ("", sarray)
Console.WriteLine ("Message: {0}", message)
/ / formatting method for converting values
DateTime waiting = new DateTime (2012, 10, 10, 17, 58, 1)
String chat = String.Format ("Message sent at {0VR t} on {0v D}"
Waiting)
Console.WriteLine ("Message: {0}", chat)
Console.ReadKey ()
}
}
}
When the above code is compiled and executed, it produces the following results:
Full Name: RowanAtkinsonGreetings: HelloMessage: Hello From Tutorials PointMessage: Message sent at 17:58 on Wednesday, 10 October 2012 read here, this "how to create String objects in C#" article has been introduced, want to master the knowledge of this article also need to practice and use in order to understand, if you want to know more related content of the article, welcome to follow the industry information channel.