473,320 Members | 2,092 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

String or string

I've noticed two different "String" variable declarations to choose from. One
uses an upper case "S" and the other uses a lower case "s". The upper case
appears in a light green color, while the lower case appears as blue. If I go
to the the variable's definition the same definition appears for each, which
suggests to me these must be the same type.

Is there actually a different meaning for each type and what would this
difference be? And, if different, is one better to use than the other, with
performance in mind?

Can anyone shed some light on this for me?

Thanks.
Oct 14 '08 #1
7 1574
"Greg" <Ac**********@newsgroups.nospamwrote in message
news:ED**********************************@microsof t.com...
I've noticed two different "String" variable declarations to choose from.
One
uses an upper case "S" and the other uses a lower case "s". The upper case
appears in a light green color, while the lower case appears as blue. If I
go
to the the variable's definition the same definition appears for each,
which
suggests to me these must be the same type.

Is there actually a different meaning for each type and what would this
difference be? And, if different, is one better to use than the other,
with
performance in mind?
"string" is a compiler synonym for System.String (in the same way as "int"
is a synonym for System.Int32), and appears blue because it is a reserved
word.
"String", since you are already "using System;", becomes System.String (and
appears light green because it is a class name).

So in both cases you end up with a System.String. There shouldn't be any
difference in the compiled code.

Oct 14 '08 #2
System.String is the actual type. "string" is effectively an alias for
System.String.

System.String s = "";
string s2 = ""

The compiler alias "string" just maps to System.String. Same with the other
types.

"Greg" <Ac**********@newsgroups.nospamwrote in message
news:ED**********************************@microsof t.com...
I've noticed two different "String" variable declarations to choose from.
One
uses an upper case "S" and the other uses a lower case "s". The upper case
appears in a light green color, while the lower case appears as blue. If I
go
to the the variable's definition the same definition appears for each,
which
suggests to me these must be the same type.

Is there actually a different meaning for each type and what would this
difference be? And, if different, is one better to use than the other,
with
performance in mind?

Can anyone shed some light on this for me?

Thanks.
Oct 14 '08 #3
MC

"Greg" <Ac**********@newsgroups.nospamwrote in message
news:ED**********************************@microsof t.com...
I've noticed two different "String" variable declarations to choose from.
One
uses an upper case "S" and the other uses a lower case "s". The upper case
appears in a light green color, while the lower case appears as blue. If I
go
to the the variable's definition the same definition appears for each,
which
suggests to me these must be the same type.

Is there actually a different meaning for each type and what would this
difference be? And, if different, is one better to use than the other,
with
performance in mind?
String and string mean the same thing but are in two different series of
names.

There is a C# series of names (string, int, etc.) and a .NET
language-independent series (String, Int32, etc.). Many types exist only in
the second series of names. When a type has names in both series, you can
use either one.
Oct 14 '08 #4

"MC" <fo**************@www.ai.uga.edu.slash.mcwrote in message
news:es**************@TK2MSFTNGP05.phx.gbl...
>
"Greg" <Ac**********@newsgroups.nospamwrote in message
news:ED**********************************@microsof t.com...
>I've noticed two different "String" variable declarations to choose from.
One
uses an upper case "S" and the other uses a lower case "s". The upper
case
appears in a light green color, while the lower case appears as blue. If
I go
to the the variable's definition the same definition appears for each,
which
suggests to me these must be the same type.

Is there actually a different meaning for each type and what would this
difference be? And, if different, is one better to use than the other,
with
performance in mind?

String and string mean the same thing but are in two different series of
names.

There is a C# series of names (string, int, etc.) and a .NET
language-independent series (String, Int32, etc.). Many types exist only
in the second series of names. When a type has names in both series, you
can use either one.
Greg, I would use string as it is the *norm* in most source code. The same
can be said for int but it has a few caveats, e.g. if you are working in a
code base where you delve in and out of using 32 and 64 bit ints then it may
make sense to be explicit, i.e. Int32 (not int), Int64 - this seems to
provide a nice differentiation between the two.

Granville

Oct 14 '08 #5
As already have been said in the thread, they result in the same type.

It's only in a few situations that the CRL type and the C# alias are not
fully interchangeable. For example as a base type for enums:

enum test1 : int { A, B, C }; // int is valid
enum test2 : Int32 { A, B, C }; // Int32 is not valid

--
Göran Andersson
_____
http://www.guffa.com
Oct 15 '08 #6
Greg wrote:
I've noticed two different "String" variable declarations to choose from. One
uses an upper case "S" and the other uses a lower case "s". The upper case
appears in a light green color, while the lower case appears as blue. If I go
to the the variable's definition the same definition appears for each, which
suggests to me these must be the same type.

Is there actually a different meaning for each type and what would this
difference be? And, if different, is one better to use than the other, with
performance in mind?
No difference just a matter of style.

I believe string (C# language style) is favored over
String (.NET framework style) by the majority.

Arne
Oct 15 '08 #7
Granville Barnett wrote:
Greg, I would use string as it is the *norm* in most source code. The
same can be said for int but it has a few caveats, e.g. if you are
working in a code base where you delve in and out of using 32 and 64 bit
ints then it may make sense to be explicit, i.e. Int32 (not int), Int64
- this seems to provide a nice differentiation between the two.
Depends on whether you consider knowing that int is 32 bit in C#
is a basic requirement for all C# developers.

I tend to think so.

Arne
Oct 15 '08 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

16
by: Krakatioison | last post by:
My sites navigation is like this: http://www.newsbackup.com/index.php?n=000000000040900000 , depending on the variable "n" (which is always a number), it will take me anywhere on the site......
5
by: Stu Cazzo | last post by:
I have the following: String myStringArray; String myString = "98 99 100"; I want to split up myString and put it into myStringArray. If I use this: myStringArray = myString.split(" "); it...
9
by: John F Dutcher | last post by:
I use code like the following to retrieve fields from a form: recd = recd.append(string.ljust(form.getfirst("lname",' '),15)) recd.append(string.ljust(form.getfirst("fname",' '),15)) etc.,...
10
by: Angus Leeming | last post by:
Hello, Could someone explain to me why the Standard conveners chose to typedef std::string rather than derive it from std::basic_string<char, ...>? The result of course is that it is...
2
by: Andrew | last post by:
I have written two classes : a String Class based on the book " C++ in 21 days " and a GenericIpClass listed below : file GenericStringClass.h // Generic String class
29
by: zoro | last post by:
Hi, I am new to C#, coming from Delphi. In Delphi, I am using a 3rd party string handling library that includes some very useful string functions, in particular I'm interested in BEFORE (return...
2
by: Badass Scotsman | last post by:
Hello, Using VB and ASP,NET I would like to be able to search a STRING for a smaller STRING within, based on the characters which appear before and after. For example: String1 = " That was...
15
by: morleyc | last post by:
Hi, i would like to remove a number of characters from my string (\t \r \n which are throughout the string), i know regex can do this but i have no idea how. Any pointers much appreciated. Chris
11
by: ramu | last post by:
Hi, Suppose I have a string like this: "I have a string \"and a inner string\\\" I want to remove space in this string but not in the inner string" In the above string I have to remove...
8
by: drjay1627 | last post by:
hello, This is my 1st post here! *welcome drjay* Thanks! I look answering questions and getting answers to other! Now that we got that out of the way. I'm trying to read in a string and...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.