Difference between string and String?

R

Ronald S. Cook

I notice there are many terms in the .NET Framework like string and String.
What's the difference? Which should I use?

I also see int and Int32. They are the same?

Thanks,
Ron
 
?

=?ISO-8859-1?Q?Arne_Vajh=F8j?=

Ronald said:
I notice there are many terms in the .NET Framework like string and String.
What's the difference? Which should I use?

I also see int and Int32. They are the same?

They are the same.

int and string are types in the C# language.

Int32 and String are types in the .NET framework.

And the C# types are mapped to the .NET types.

My wording. MS may explain it differently.

Arne
 
M

Michael

*I notice there are many terms in the .NET Framework like string and String.
* What's the difference? Which should I use?
*
* I also see int and Int32. They are the same?
*
* Thanks,
* Ron
*
*

Ron,

They're the same.
String comes from the .NET class System.String and string (lower case) is a
C# alias for System.String.
I often see devs interchange the .NET and C# aliases for various data types;
not sure why though.

-MH
 
C

clintonG

They do seem to be different...
The Split method is not accessible when trying to use it as string.Split but
it is as String.Split
If they are the same how could that be?


<%= Clinton Gallagher
NET csgallagher AT metromilwaukee.com
URL http://clintongallagher.metromilwaukee.com/
MAP 43°2'17"N 88°2'37"W : 43°2'17"N 88°2'37"W
 
W

William Stacey [MVP]

Split is an instance method, not a static member. So at least on 2.0, you
can not do "string.Split" or "String.Split". You can with an string
instance.

--
William Stacey [MVP]

| They do seem to be different...
| The Split method is not accessible when trying to use it as string.Split
but
| it is as String.Split
| If they are the same how could that be?
|
|
| <%= Clinton Gallagher
| NET csgallagher AT metromilwaukee.com
| URL http://clintongallagher.metromilwaukee.com/
| MAP 43°2'17"N 88°2'37"W : 43°2'17"N 88°2'37"W
|
| | > | > *I notice there are many terms in the .NET Framework like string and
| > String.
| > * What's the difference? Which should I use?
| > *
| > * I also see int and Int32. They are the same?
| > *
| > * Thanks,
| > * Ron
| > *
| > *
| >
| > Ron,
| >
| > They're the same.
| > String comes from the .NET class System.String and string (lower case)
is
| > a C# alias for System.String.
| > I often see devs interchange the .NET and C# aliases for various data
| > types; not sure why though.
| >
| > -MH
| >
| >
|
|
 
R

Russell Mangel

Most of the code I have seen uses int for Int32,
and string for String. But the choice is yours.

In most cases using the alias types will be identical
to the CLR type. However, value types like int
(Int32), may not. Consider the following two loops:

for (int i = 0; i < int.MaxValue; i++)
{
// Loop runs to Int32.MaxValue on 32-bit cpus.
// Loop runs to Int64.MaxValue on 64-bit cpus.

// The big difference here is this loop could have
// more loops on 64-bit cpus.
// Can your program tolerate this?
}

// Using CLR Types
for (Int32 i = 0; i < Int32.MaxValue; i++)
{
// This loop will have the same number of iterations
// on 32-bit or 64 bit cpus.
}

Personally I use the CLR types exclusively. So
when I say Int32 i = 9; I know will will be 32bits
and not 64 bits.

Russell Mangel
Las Vegas, NV
 
M

Marc Gravell

No, according to the c# spec (3.4.2 and 4.1.4), int is System.Int32
*always* (lessons learnt from the past...). IntPtr.Size changes to
match the OS, however.

Marc
 
J

Jon Skeet [C# MVP]

Russell Mangel said:
Most of the code I have seen uses int for Int32,
and string for String. But the choice is yours.

In most cases using the alias types will be identical
to the CLR type. However, value types like int
(Int32), may not. Consider the following two loops:

for (int i = 0; i < int.MaxValue; i++)
{
// Loop runs to Int32.MaxValue on 32-bit cpus.
// Loop runs to Int64.MaxValue on 64-bit cpus.

// The big difference here is this loop could have
// more loops on 64-bit cpus.
// Can your program tolerate this?
}

Any evidence for this? I don't believe it's the case at all. int
*always* means Int32 as far as I've ever seen in the standard.
// Using CLR Types
for (Int32 i = 0; i < Int32.MaxValue; i++)
{
// This loop will have the same number of iterations
// on 32-bit or 64 bit cpus.
}

Personally I use the CLR types exclusively. So
when I say Int32 i = 9; I know will will be 32bits
and not 64 bits.

Would you feel differently if the above was proved not to be true? The
spec is very clear on the matter. For example, from 11.1.5 (ECMA
numbering for C# 2.0):

<quote>
The int type represents signed 32-bit integers with values from
=3F2147483648 to 2147483647, inclusive.
</quote>
 
M

mpetrotta

Russell said:
Most of the code I have seen uses int for Int32,
and string for String. But the choice is yours.

In most cases using the alias types will be identical
to the CLR type. However, value types like int
(Int32), may not. Consider the following two loops:

for (int i = 0; i < int.MaxValue; i++)
{
// Loop runs to Int32.MaxValue on 32-bit cpus.
// Loop runs to Int64.MaxValue on 64-bit cpus.

// The big difference here is this loop could have
// more loops on 64-bit cpus.
// Can your program tolerate this?
}

// Using CLR Types
for (Int32 i = 0; i < Int32.MaxValue; i++)
{
// This loop will have the same number of iterations
// on 32-bit or 64 bit cpus.
}

Beg to differ. Running on a quad Xeon (EM64T) box, with Windows Server
2003 64-bit Enterprise Edition:

Console.WriteLine("int.MaxValue = " + int.MaxValue);
Console.WriteLine("Int32.MaxValue = " + Int32.MaxValue);
Console.WriteLine("Int64.MaxValue = " + Int64.MaxValue);

int.MaxValue = 2147483647
Int32.MaxValue = 2147483647
Int64.MaxValue = 9223372036854775807

And Jon's already pointed out the spec reference.

Michael
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top