C# Tutorials and offshore development in India
    Tutorials   Resources   Forum   Reviews   Communities   Interview   Jobs   Projects   Training   Your Ad Here    
Silverlight Games | Mentor | Code Converter | Articles | Code Factory | Computer Jokes | Members | Peer Appraisal | IT Companies | Bookmarks | Polls | Revenue Sharing | Lobby | Gift Shop |


Prizes & Awards
My Profile



Active Members
TodayLast 7 Days more...






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

Author: reddy    31 Mar 2006Member Level: SilverRating: 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



Author: HimaBindu Veeramachaneni    04 Apr 2006Member Level: DiamondRating: 2 out of 52 out of 5     Points: 2

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

http://dotnetspider.com/mentors/18-HimaBindu-Veeramachaneni.aspx?tab=details'



Author: Pratap Chandra Das    16 Apr 2008Member Level: BronzeRating: 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.)



Author: Bunty    21 Nov 2008Member Level: DiamondRating: 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
S.S.Bajoria



Author: Phani Kumar    21 Nov 2008Member Level: GoldRating: 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



Author: Syed Shakeer Hussain     24 Nov 2008Member Level: DiamondRating: 2 out of 52 out of 5     Points: 0

String is a Class


string is a datatype


Thanks & Regards!
Syed Shakeer Hussain



Author: shareef    07 Dec 2008Member Level: GoldRating: 2 out of 52 out of 5     Points: 0

aliases defined
string->System.String



Author: Ali Adravi    11 Dec 2008Member Level: SilverRating: 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



Author: raja    03 Jan 2009Member Level: BronzeRating: 2 out of 52 out of 5     Points: 0

both are same man


Author: navaskhan    21 Jan 2009Member Level: SilverRating: 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.

——————————————————-



Author: Vikram Singh Kshatriya    11 Feb 2009Member Level: GoldRating: 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: .NET

Related Messages



dotNet Slackers

About Us    Contact Us    Privacy Policy    Terms Of Use