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#
Related
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.
This question already has answers here:
What's the main difference between int.Parse() and Convert.ToInt32
(13 answers)
Closed 9 years ago.
I would like to know if there is any difference between the captioned two methods?
string str = "14.75";
Console.WriteLine(Decimal.Parse(str));
Console.WriteLine(Convert.ToDecimal(str));
Can anyone please let me know? Thanks.
Decimal.Parse only supports parsing string values, whereas Convert takes other types as well, like, object, int, byte, DateTime etc.
This question already has answers here:
How can one get an absolute or normalized file path in .NET?
(4 answers)
Closed 9 years ago.
How to get canonical file name by non-canonical one.
E.g. I want to call function which converts "C:\Program files\..\Windows\aaa.txt" to "C:\Windows\aaa.txt"
I am looking for something like Java File.getCanonicalPath()
You can use the Path.GetFullPath method for this.
Example:
Console.WriteLine(Path.GetFullPath(#"C:\Program files\..\Windows\aaa.txt"));
Output:
C:\Windows\aaa.txt
System.IO.Path.GetFullPath("C:/Program files/../Windows/aaa.txt")
will return
"C:\\Windows\\aaa.txt"
Here is my suggestion:
string path = Path.GetFullPath(#"C:\Program files\..\Windows\aaa.txt");
This question already has answers here:
Closed 12 years ago.
Possible Duplicate:
Custom numeric format string to always display the sign
To format a double to certain precision in C# I write this:
d.ToString("#0.00");
What if I want to force a the sign to appear..
e.g
+2.54 and -2.54
Hope this will work.
YourDoublenumber.ToString("+#;#");
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.