difference between string and String in .net

Posted by Shanky11 under ASP.NET on 10/26/2012 | Points: 10 | Views : 1004 | Status : [Member] | Replies : 5
difference between string and String in .net

when we write like this
string s="shankar";
what is s here is it object or variable
If any one knows please clear it




Responses

Posted by: Ranjeet_8 on: 10/26/2012 [Member] [MVP] Gold | Points: 25

Up
0
Down
s is object
string is recommended for objects and String is recommended for classes. In reflection you should use String.
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.


string :
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:

String :
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



Shanky11, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Shanky11 on: 10/26/2012 [Member] Starter | Points: 25

Up
0
Down
if s is object then what is string
System.String Is what??????????


Shanky11, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Kaushikmaheta on: 10/26/2012 [Member] Starter | Points: 25

Up
0
Down
see this link help to..........
http://forums.asp.net/t/1170115.aspx/1

Regards
Kaushik Maheta

Shanky11, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Jayakumars on: 10/28/2012 [Member] [MVP] Bronze | Points: 25

Up
0
Down
hi

string delcaration string datatypes and others convert to string
String is collection of some string metod have the classes.



Mark as Answer if its helpful to you

Shanky11, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: K011gusain89 on: 10/29/2012 [Member] Starter | Points: 25

Up
0
Down
They're the same.
String comes from the .NET class System.String and string (lower case) is a
C# alias for System.String.

Shanky11, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response