About 105,000 results
Open links in new tab
  1. Different Ways to Initialize a String in C# - Code Maze

    May 23, 2023 · In this article, we will discuss how we can initialize a string in C# and the recommended best practices to follow. We will explore different approaches and techniques that enable us to achieve proper initialization and efficient utilization of strings.

  2. Strings - C# | Microsoft Learn

    Nov 22, 2024 · You can declare and initialize strings in various ways, as shown in the following example: // Initialize to null. string? message2 = null; // Initialize as an empty string. // Use the Empty constant instead of the literal "". string message3 = System.String.Empty;

  3. c# - Options for initializing a string array - Stack Overflow

    Sep 3, 2013 · string[] myString = new string[]{"string1", "string2"}; or. string[] myString = new string[4]; myString[0] = "string1"; // etc. Advanced: From a List. list<string> = new list<string>(); //... read this in from somewhere string[] myString = list.ToArray(); From StringCollection

  4. c# - How to initialize a list of strings (List<string>) with many ...

    In 2.0 you must use it like this: List<string> optionList = new List<string>() { "AdditionalCardPersonAdressType", /* rest of elements */ };. Note the () here: new List<string>(). It's a C# 3 language feature and has nothing to do with the version of the framework you're using.

  5. C# Strings - GeeksforGeeks

    Mar 4, 2025 · A string is represented by the class System.String. The “string” keyword is an alias for System.String class, and instead of writing System.String one can use String, which is a shorthand for System.String class. So we can say that both string and String can be used as an alias of System.String class.

  6. .net - In C#, should I use string.Empty or String.Empty or "" to ...

    Nov 5, 2008 · In C#, I want to initialize a string value with an empty string. How should I do this? What is the right way, and why? string willi = string.Empty; or string willi = String.Empty; or string wi...

  7. C# (C Sharp) | Strings - Codecademy

    Mar 14, 2023 · There are many different ways to declare and initialize a string in C#. The following example lists a number of them: // Declare without initializing. // Declare using System.String. // Initialize with a string literal. string myString3 = "Hello World!"; // …

  8. Initializing Strings | Manipulating Strings in C# - Peachpit

    Initializing Strings. When you declare a variable of type string, the runtime doesn't automatically create a buffer to hold that string. Like other reference types in which the actual object isn't created until you use the new operator, string buffers aren't created until you initialize the string. To declare and initialize a string variable:

  9. Initializing a String in C# | NEURALWORD

    Sep 3, 2023 · Initializing a string means assigning a value to it, either when it is declared or at a later stage. In C#, there are multiple ways to initialize a string, depending on the requirements and preferences of the programmer. This article will discuss some common techniques for initializing strings in C#. 1. Initializing with a Literal

  10. C# string - C# Tutorial

    First, define the message string variable and initialize it to the string literal "C#". Second, concatenate the message string variable with another string literal " string!". Third, show the message string to the console.

  11. Some results have been removed
Refresh