What\'s the difference between double quotes and single quote in C#?
I coded a program to count how many words are in a file
using System;
using Syst
when you say string s = "this string" then s[0] is a char at at specific index in that string (in this case s[0] == 't')
So to answer your question, use double quotes or single quotes, you can think of the following as meaning the same thing:
string s = " word word";
// check for space as first character using single quotes
if(s[0] == ' ') {
// do something
}
// check for space using string notation
if(s[0] == " "[0]) {
// do something
}
As you can see, using a single quote to determine a single char is a lot easier than trying to convert our string into a char just for testing.
if(s[0] == " "[0]) {
// do something
}
is really like saying:
string space = " ";
if(s[0] == space[0]) {
// do something
}
Hopefully I did not confuse you more!