Powered by Blogger.

Saturday, October 28, 2017

What is the difference between String and string in C#.Net?



Here we will see what is the difference between String and string in C#.Net.

Actually there is no difference between String and string.

Also read my previous posts: How to call non static method inside main in C#.Net console application?, What are the differences between Hashtable and Dictionary in C#.Net? and also you can check How to split a string by another string in C#.Net?

string is an alias for System.String in C#.Net. Both of them are compiled to System.String.

But we need to just follow a guideline.

If you are referring to a Class then you should use String. And if you are referencing to an object then we should use string.

Example:
String.Format ("Hello {0}!", name);

string name = "Bijay";

To use String in a class we need to write the using System; statement.

And also string is a reserved keyword, so we can not use as variable name.





0 comments

Post a Comment