c# data type declaration

  • Thread starter Thread starter ditwal001
  • Start date Start date
D

ditwal001

hi folks

which datatype declaration is to be preferred in c# .net?

ex.
System.String sTemp = "";
System.Int64 = 0;

or

string sTemp = "";
int = 0;

what is differentiated thereby?

thanx and have a nice day.
 
ditwal001 said:
hi folks

which datatype declaration is to be preferred in c# .net?

They're the same thing. I always go the route of least typing.

BTW, int is actually System.Int32, not Int64.

--
There are 10 kinds of people. Those who understand binary and those who
don't.

http://code.acadx.com
(Pull the pin to reply)
 
Theoretically the exact meaning of int and string (and other variables) can
change over time.

For example, in many flavors of C/C++, int was at one time 16 bit and
changed meaning to be 32 bit (this happened as processors moved from being
16 bit to 32 bit).

The meaning of a string variable has also changed from 8-bit per character
to 16-bit per character as Unicode became supported (though I'm not aware of
a language that defined the specific term "string" first as 8 then as 16 bit
character arrays... maybe VB, but I didn't do anything with VB until VB
strings were already Unicode).

The moral is, if you want to be certain of the number of bits in your
integer, use System.Int32, etc.

Eric
 
They are USUALLY the same thing, but not always. The compiler ALWAYS binds
"int" to the one and only System.Int32 in mscorlib.dll, but System.Int32 is
looked up using the normal type resolution rules meaning it is subject to
the types in the current namespace, using clauses, etc. Now granted It's
very unlikely that anybody will ever make another type named System.Int32,
but there's plenty of people using a class or namespace named System. and
this could cause some really strange compiler errors.
 
Actually that is true for C/C++ because they wanted to be so close to the
hardware that they literally defined int as being platform specific, such
that the only grantee you had when switching compilers or platforms was that
a long was never SMALLER than int.

C# has taken a very different route and has explicitly stated the sizes of
these data types. See section 4.1.5 of the C# language spec for the sizes
and ranges.
 
Eric Johannsen said:
Theoretically the exact meaning of int and string (and other variables) can
change over time.

Nope. Whereas the C specification only gives certain minimal
conditions, the C# specification is very clear on exactly what "int",
"long" etc mean.
 
Back
Top