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   Responses: 11



i want difference between ----following return type of function getData() and variable declared in function block.
public String getData()
{
doc = new XmlDocument();
doc.LoadXml(objectXml);
OleDbCommand cmdLoginValidate;
string strSql;
}




Responses

#46070    Author: reddy      Member Level: Silver      Member Rank: 0     Date: 31/Mar/2006   Rating: 2 out of 52 out of 5     Points: 2

Hi nilesh, please have a glimpse on this provided by microsoft.

http://blogs.msdn.com/csharpfaq/archive/2004/03/12/88418.aspx



 
#46418    Author: HimaBindu Vejella      Member Level: Gold      Member Rank: 42     Date: 04/Apr/2006   Rating: 2 out of 52 out of 5     Points: 2

string is an alias name of String that is created by ms

http://himabinduvejella.blogspot.com
http://sysntaxhelp.com/asp.net
http://groups.google.com/group/mugh
Hima's Tech Blog



 
#215917    Author: Pratap Chandra Das      Member Level: Bronze      Member Rank: 0     Date: 16/Apr/2008   Rating: 2 out of 52 out of 5     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: 2 out of 52 out of 5     Points: 5

Hi,

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

http://jalpesh.blogspot.com/2007/10/what-is-diffrence-between-string-and.html

http://social.msdn.microsoft.com/Forums/en-US/csharplanguage/thread/0e0297ad-fc05-42d1-a994-d1baba433ff6/

http://bytes.com/forum/thread530368.html

Regards
S.S.Bajoria


Thanks & Regards


Bunty

Expertise Dot Net On Earth



 
#319517    Author: Phani Kumar      Member Level: Gold      Member Rank: 0     Date: 21/Nov/2008   Rating: 2 out of 52 out of 5     Points: 6

hi nilesh ashokrao narkhede,


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


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,
Phani



 
#320558    Author: Syed Shakeer Hussain       Member Level: Gold      Member Rank: 106     Date: 24/Nov/2008   Rating: 2 out of 52 out of 5     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: 2 out of 52 out of 5     Points: 0

aliases defined
string->System.String



 
#328248    Author: Ali Adravi      Member Level: Silver      Member Rank: 0     Date: 11/Dec/2008   Rating: 2 out of 52 out of 5     Points: 2

Hi Hussain,

You are wrong.
string is the alias of String and nothing difference there.

Hope it will clear your point.

ALI Adravi
www.metaoption.com



 
#334731    Author: raja      Member Level: Silver      Member Rank: 0     Date: 03/Jan/2009   Rating: 2 out of 52 out of 5     Points: 0

both are same man


 
#339242    Author: navaskhan      Member Level: Gold      Member Rank: 929     Date: 21/Jan/2009   Rating: 2 out of 52 out of 5     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).

using System;

…………..

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: 2 out of 52 out of 5     Points: 1

String is class in System namespace and string is just an alias for that created by MS.


 
Post Reply

 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.



Next : Is there any expert to solve this?
Previous : what is a resource file...
Return to Discussion Forum
Post New Message
Category:

Related Messages
Active Members
TodayLast 7 Daysmore...

Awards & Gifts
Copyright © SpiderWorks Technologies Pvt Ltd., Kochi, India
2005 - 2012 All Rights Reserved.
.NET and other trademarks mentioned in this site belong to Microsoft and other respective trademark owners.
Articles, tutorials and all other content offered here is for educational purpose only.
We are not associated with Microsoft or its partners.