Talk to Webmaster Tony John
Forums » .NET » .NET »
what is difference between String and string(data type) in c#?
Posted Date: 30 Mar 2006 Posted By:: nilesh ashokrao narkhede Member Level: Bronze Member Rank: 0 Points: 1
i want difference between ----following return type of function getData() and variable declared in function block.
public String getData()
doc = new XmlDocument();
|#46070 Author: reddy Member Level: Silver Member Rank: 0 Date: 31/Mar/2006 Rating: Points: 2|
Hi nilesh, please have a glimpse on this provided by microsoft.
|#46418 Author: HimaBindu Vejella Member Level: Gold Member Rank: 42 Date: 04/Apr/2006 Rating: Points: 2|
string is an alias name of String that is created by ms
Hima's Tech Blog
|#215917 Author: Pratap Chandra Das Member Level: Bronze Member Rank: 0 Date: 16/Apr/2008 Rating: Points: 2|
In .Net for every Value type there is an Equivalent Class
Like : -
int (value type) System.Int (reference type)
bool ( " " ) System.Bool ( " " )
similarly if we declare string internally it creates a string class , we use it as value type in program,
While String represent System.String Class.
In both cases we can have the same methods / properties (string and String.)
|#319362 Author: Bunty Member Level: Gold Member Rank: 15 Date: 21/Nov/2008 Rating: Points: 5|
There is no difference between string and String. string is a alias created by Microsoft for System.string.
For more details check the following website
Thanks & Regards
Expertise Dot Net On Earth
|#319517 Author: Phani Kumar Member Level: Gold Member Rank: 0 Date: 21/Nov/2008 Rating: Points: 6|
hi nilesh ashokrao narkhede,
The string type represents a sequence of zero or more Unicode characters. string is an alias for String in the .NET Framework.
'string' is the intrinsic C# datatype, and is an alias for the system provided type "System.String". The C# specification states that as a matter of style the keyword ('string') is preferred over the full system type name (System.String, or String).
Although string is a reference type, the equality operators (== and !=) are defined to compare the values of string objects, not references. This makes testing for string equality more intuitive. For example:
A String object is called immutable (read-only) because its value cannot be modified once it has been created. Methods that appear to modify a String object actually return a new String object that contains the modification. If it is necessary to modify the actual contents of a string-like object
Difference between string & String :
---------- ------- ------ - ------
the string is usually used for declaration while String is used for accessing static string methods
we can use 'string' do declare fields, properties etc that use the predefined type 'string', since the C# specification tells me this is good style.
we can use 'String' to use system-defined methods, such as String.Compare etc. They are originally defined on 'System.String', not 'string'. 'string' is just an alias in this case.
we can also use 'String' or 'System.Int32' when communicating with other system, especially if they are CLR-compliant. I.e. - if I get data from elsewhere, I'd deserialize it into a System.Int32 rather than an 'int', if the origin by definition was something else than a C# system.
Thanks & regards,
|#320558 Author: Syed Shakeer Hussain Member Level: Gold Member Rank: 106 Date: 24/Nov/2008 Rating: Points: 0|
String is a Class
string is a datatype
Thanks & Regards!
Syed Shakeer Hussain
|#326405 Author: shareef Member Level: Gold Member Rank: 0 Date: 07/Dec/2008 Rating: Points: 0|
|#328248 Author: Ali Adravi Member Level: Silver Member Rank: 0 Date: 11/Dec/2008 Rating: Points: 2|
You are wrong.
string is the alias of String and nothing difference there.
Hope it will clear your point.
|#334731 Author: raja Member Level: Silver Member Rank: 0 Date: 03/Jan/2009 Rating: Points: 0|
both are same man
|#339242 Author: navaskhan Member Level: Gold Member Rank: 929 Date: 21/Jan/2009 Rating: Points: 5|
This is what MSDN has to say about this :
In C#, the string keyword is an alias for String. Therefore, String and string are equivalent, and you can use whichever naming convention you prefer.
So in other words string is equivalent to System.String ( data type defined in .net framework).
string s1 = “ABC”;
String s2 = “DEF”;
above line of code will compile and work as expected.
// using System;
string s1 = “ABC”;
String s2 = “DEF”;
but above line of code will produce compile time error as it can not identify the “String” data type.
So in short, (in c#) use either “string” or “System.String”. Functionally, using any of these doesn’t make any difference. The same explaination applies to other data types i.e. char & Char, object & Object etc.
|#346175 Author: Vikram Singh Kshatriya Member Level: Gold Member Rank: 1749 Date: 11/Feb/2009 Rating: Points: 1|
String is class in System namespace and string is just an alias for that created by MS.
| ||This thread is locked for new responses. Please post your comments and questions as a separate thread.|
If required, refer to the URL of this page in your new post.
Active MembersTodayLast 7 Daysmore...