Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

string

Status
Not open for further replies.

goransaler

IS-IT--Management
Mar 6, 2003
56
SE
A question to you gurus
I´m trying to learn C# and seen that in some doc´s
it say´s that a string is a value and simple/primitive (must be the same or?) type
or it´s a reference and class type or can it be booth

thank´s
 
The string type is a sealed class type that inherits directly from object.
Instances of the string class represent an IMMUTABLE, fixed-length string of Unicode characters.
A String is called immutable because its value cannot be modified once it has been created
The string keyword is simply an alias for the predefined System.String class.
Values of the string type can be written as string literals:
C# supports two forms of string literals: regular string literals and verbatim string literals.
A regular string literal consists of zero or more characters enclosed in double quotes, as in "hello", and may include both simple escape sequences (such as \t for the tab character), hexadecimal escape sequences, and Unicode escape sequences.
A verbatim string literal consists of an @ character followed by a double-quote character, zero or more characters, and a closing double-quote character.
string c = "hello \t world"; // hello world
string d = @"hello \t world"; // hello \t world

object ob1 = "hello";
object ob2 = "hello";
string so1 = "hello";
string so2 ="hello";
so2.Replace('l','x'); // so2 unchanged
so2 = so1.Replace('l','x'); // so2 is "hexxo";
public void FixSection( ref string section)
{
section = "blabla";
}


string mySection = "";
FixSection(ref mySection); // mySection will be "blabla".

object [] sKey = new object[4];
sKey[0] = "hello1";
skey[1]= "hello2";
....
If you want to modify the value of a string use StringBuilder object.

-obislavu-
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top