Difference between String and string C# [duplicate] - c#

This question already has answers here:
What is the difference between String and string in C#?
(66 answers)
Closed 9 years ago.
Sorry about this dumb question, but i´ve recently found out that you can declare a String or string variable at C#. I would like to know the difference between them, which one is used at specific situations, etc. Thanks for the help and for your time.

There is no difference String is the Class name and string is the alias.
The generaly rule of thumb that I have followed is that if you declare a variable use the alias.
string foo = "bar";
If you call a method, use the class name
String.IsNullOrEmpty("");
It is exactly the same for the following"
Boolean and bool
Int32 and int
Double and double
etc

Related

How to check a string for a question mark? [duplicate]

This question already has answers here:
How can I check if a string contains a character in C#?
(8 answers)
Closed 5 years ago.
I want to check if an inputted string contains a question mark.
Probably quite simple but I'm new to coding.
Use String.Contains() :
string myString = "Hello world?";
bool containsQuestionMark = myString.Contains("?"); // true
For future references, use MSDN, it's filled with good documentation.
Alternatively (to Rick's answer), if you are checking just for char occurance in a string you can use IndexOf(char):
bool containsQuestionMark = myString.IndexOf('?') != -1;
There are also some minor (negligible) performance differences between two approaches, depending on the framework version being used.

explain the two approach String Type Casting In C# [duplicate]

This question already has answers here:
Difference between Convert.ToString() and .ToString()
(19 answers)
variable.ToString() vs. Convert.ToString(variable)
(2 answers)
Closed 7 years ago.
Can anyone please explain me what is the difference between these two string Type Casting method.
Type 1
int i = 90;
string b = i.ToString();
Type 2
int i = 90;
string b = Convert.ToString(i);
I want to know the major difference of using the two different approach. The 1st one is to handle the null value,we can use 'Convert.ToString(); '. And moreover I get to know that '.ToString()' can be override.
Can anyone can explain how. And which one is good to use.
Thanks in Advance.

Difference between bool/Boolean, string/String etc [duplicate]

This question already exists:
Closed 12 years ago.
Possible Duplicate:
String vs string in C#
What is the big difference between these datatypes? and were should I use it?
Short answer, there is no difference. They are just alias of each other, see
http://msdn.microsoft.com/en-us/library/ya5y69ds(VS.80).aspx for a complete list.
Have a look at: String vs string in C#

What is the difference between the type String and type string? (Uppercase first letter) [duplicate]

This question already has answers here:
Closed 12 years ago.
Possible Duplicate:
In C# what is the difference between String and string
I couldn't find the info anywhere, but I'm sure it's just a simple answer. Are they interchangeable??
Yes, they are identical. string is just the C# name for a System.String, which you can also use. See MSDN:
The string type represents a string of Unicode characters. string is an alias for System.String in the .NET Framework.
It's personal preference, but I always use string over String. I guess I like the blue color over the, uh, turquoise color offered by the default syntax highlighting.
You can see the other aliases under the C# value types on MSDN (e.g. int is really System.Int32 while long is really System.Int64).
You get this question a lot because in java there is a difference between for example Integer and int (pointer allocation). In C# there is no difference between String and string, nor there is a difference between Int32 and int etc..

Datatype String vs string in C# [duplicate]

This question already exists:
Closed 13 years ago.
When to use "String" and when to go for "string" data type in C# ?
What is the difference between them?
Thanks.
Duplicate: String vs string in C#
There is no difference. string is an alias of String. The same goes for int and Int32 etc.
They are the same. Choose one notation and stick to it.

Categories

Resources