805
votes
31answers
128k 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 ...
391
votes
21answers
231k 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 ...
43
votes
8answers
4k 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 = ...
242
votes
26answers
149k 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 ...
90
votes
8answers
40k 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 ...
169
votes
18answers
102k 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 ...
64
votes
10answers
39k views

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

What's the most efficient way to concatenate strings?
51
votes
13answers
16k views

Why .NET String is immutable?

As we all know, String is immutable. What are the reasons for String being immutable and the introduction of StringBuilder class as mutable?
96
votes
11answers
62k 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
57
votes
29answers
18k 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, ...
72
votes
8answers
8k 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 == ...
209
votes
4answers
47k views

How to escape brackets 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 ...
83
votes
9answers
61k views

Differences in string compare methods in C#

Comparing string in C# is pretty simple. In fact there are several ways to do it. I have listed some in the block below. What I am curious about are the differences between them and when one should ...
50
votes
8answers
38k views

How can I strip HTML tags from a string in ASP.NET?

Using ASP.NET, how can I strip the HTML tags from a given string reliably (i.e. not using regex)? I am looking for something like PHP's strip_tags. Example: ...

1 2 3 4 5 50
15 30 50 per page