Computer >> कंप्यूटर ट्यूटोरियल >  >> प्रोग्रामिंग >> C#

C# में String Object कैसे Create करें?


C# में String Object Create करने के लिए, नीचे दिए गए किसी भी Method का उपयोग करें।

  • String Literal को String Variable में Assign करके
  • String Class Constructor का उपयोग करके
  • String Concatenation Operator (+) का उपयोग करके
  • Property Retrieve करके या Method Call करके जो String Return करता है
  • Formatting Method Call करके Value या Object को String Representation में Convert करने के लिए

निम्न Example C# में String Object Create करने के विभिन्न तरीकों को दर्शाता है।

Example

using System; namespace Demo {    class Program {       static void Main(string[] args) {          // String Literal और String Concatenation से          string fname, lname;          fname = "Brad ";          lname = "Pitt";          char[] letters = { 'W', 'e', 'b'};          string[] sarray = { "Web", "World"};          string fullname = fname + lname;          Console.WriteLine("Full Name: {0}", fullname);          // String Constructor का उपयोग करके { 'W', 'e', 'b'};          string greetings = new string(letters);          Console.WriteLine("Greetings: {0}", greetings);          // Methods Returning String { "Web", "World" };          string message = String.Join(" ", sarray);          Console.WriteLine("Message: {0}", message);          // Formatting Method Value Convert करने के लिए          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);       }    } }

Output

Full Name: Brad Pitt Greetings: Web Message: Web World Message: Message sent at 5:58 PM on Wednesday, October 10, 2012

  1. स्ट्रिंग को जावास्क्रिप्ट ऑब्जेक्ट में कैसे बदलें? स्ट्रिंग को जावास्क्रिप्ट ऑब्जेक्ट में कैसे बदलें?

    स्ट्रिंग को जावास्क्रिप्ट ऑब्जेक्ट में बदलने का कोड निम्नलिखित है - उदाहरण <!DOCTYPE html> <html lang=en> <head> <meta charset=UTF-8 /> <meta name=viewport content=width=device-width, initial-scale=1.0 /> <title>Document</title> <style>    

  1. जावास्क्रिप्ट में मल्टीडाइमेंशनल ऑब्जेक्ट कैसे बनाएं? जावास्क्रिप्ट में मल्टीडाइमेंशनल ऑब्जेक्ट कैसे बनाएं?

    जावास्क्रिप्ट में मल्टीडाइमेंशनल ऑब्जेक्ट बनाने के लिए निम्नलिखित कोड है: उदाहरण <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8" /> <meta name="viewport" content="width=device-width, initial-scale=1.0" /> <title&

  1. Tkinter एरर मैसेज बॉक्स कैसे बनाएं? Tkinter एरर मैसेज बॉक्स कैसे बनाएं?

    Tkinter लाइब्रेरी में कई बिल्ट-इन फंक्शन्स और मेथड्स हैं जिनका उपयोग एप्लिकेशन के फंक्शनल पार्ट को इम्प्लीमेंट करने के लिए किया जा सकता है। हम Tkinter में विभिन्न पॉपअप डायलॉग बॉक्स बनाने के लिए messagebox मॉड्यूल का उपयोग कर सकते हैं। messagebox प्रॉपर्टी में विभिन्न प्रकार के बिल्ट-इन पॉपअप विंडो