893
votes
31answers
144k views

What's the difference between String and string?

In C#, what is the difference between String and string? (note the case) Example: string s = "Hello, World"; String S = "Hello, World"; Also, what are the guidelines for the use of each?
264
votes
0answers
56k views

String vs string in C# [duplicate]

Possible Duplicate: In C# what is the difference between String and string In C# the string keyword (highlighted in Visual Studio as a data type) is just a shortcut to the String class ...
425
votes
22answers
254k views

.NET String to byte Array C#

How do I convert a string to a byte array in .NET (C#)? Update: Also please explain why encoding should be taken into consideration. Can't I simply get what bytes the string has been stored in? Why ...
49
votes
8answers
5k views

What's the @ in front of a string in C#?

This is a .NET question for C# (or possibly VB.net), but I am trying to figure out what's the difference between the following declarations: string hello = "hello"; vs. string hello_alias = ...
257
votes
26answers
161k views

C# String enums

I have the following enumeration: public enum AuthenticationMethod { FORMS = 1, WINDOWSAUTHENTICATION = 2, SINGLESIGNON = 3 } The problem however is that I need the word "FORMS" when I ...
96
votes
8answers
43k views

In C#, why is String a reference type that behaves like a value type?

A String is a reference type even though it has most of the characteristics of a value type such as being immutable and having == overloaded to compare the text rather than making sure they reference ...
181
votes
19answers
110k views

How would you count occurences of a string within a string (C#)?

I am doing something where I realised I wanted to count how many /s I could find in a string, and then it struck me, that there were about several ways to do it, but couldn't decide on what the best ...
54
votes
13answers
17k views

Why .NET String is immutable? [duplicate]

As we all know, String is immutable. What are the reasons for String being immutable and the introduction of StringBuilder class as mutable?
69
votes
10answers
42k views

What's the best string concatenation method using C#?

What's the most efficient way to concatenate strings?
59
votes
29answers
19k views

C# String output: format or concat?

Let's say that you want to output or concat strings, what style do you prefer: var p = new { FirstName = "Bill", LastName = "Gates" }; Console.WriteLine("{0} {1}", p.FirstName, ...
74
votes
8answers
9k views

Are string.Equals() and == operator really same?

Are they really same? Today, I ran into this problem. Here is the dump from the Immediate Window: ?s "Category" ?tvi.Header "Category" ?s == tvi.Header false ?s.Equals(tvi.Header) true ?s == ...
97
votes
12answers
65k views

How do I replace multiple spaces with a single space in C#?

How can I replace multiple spaces in a string with only one space in C#? Example: 1 2 3 4 5 would be: 1 2 3 4 5
21
votes
19answers
27k views

c# evaluating string “3*(4+2)” yield int 18 [duplicate]

Is there a function the the .Net framework that can evaluate a numering expression contained in a string and return the numeric result? IE: string mystring = "3*(2+4)"; int result = ...
229
votes
4answers
51k views

How to escape brackets (curly braces) in a format string in .Net

How can brackets be escaped in a C# format string so, something like: String val = "1,2,3" String.Format(" foo {{0}}", val); doesn't throw a parse exception but actually outputs the string "foo ...
38
votes
13answers
23k views

When is it better to use String.Format vs string concatenation?

I've got a small piece of code that is parsing an index value to determine a cell input into Excel. It's got me thinking... What's the difference between xlsSheet.Write("C" + rowIndex.ToString(), ...

1 2 3 4 5 54
15 30 50 per page