Miscellaneous Newbie questions

D

Dom

No sense in putting each one in a different post.

1. What is the difference between String and string (upper- and lower-
case)?
2. Which is preferable, IntVariable.ToString() or
Convert.ToString(IntVariable)?
3. Since String is a class, why is there no String.ToClass, but there
is a StrVariable.ToString?
4. If int is a primitive, why am I allowed to say int i = new int()?

Others to come ...
 
?

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

Dom said:
1. What is the difference between String and string (upper- and lower-
case)?
None.

2. Which is preferable, IntVariable.ToString() or
Convert.ToString(IntVariable)?

That is debatable. I prefer the first.
3. Since String is a class, why is there no String.ToClass, but there
is a StrVariable.ToString?

What should ToClass do ??

Object has a ToString so all classes has that. String has
overriden it with something usefull.
4. If int is a primitive, why am I allowed to say int i = new int()?

Why not ?

new is not reserved for reference types.

Arne
 
D

Dom

3. Since String is a class, why is there no String.ToClass, but there
What should ToClass do ??

Sorry, I meant String.ToString(). Don't all classes have this method?
Why not ?
new is not reserved for reference types.

I thought "new" created a new object on the heap. That is how it
works in Java. What object is being created with a primitive?

BTW, did you used to post on a VAX/VMS newsgroup?
 
J

Jon Skeet [C# MVP]

Dom said:
Sorry, I meant String.ToString(). Don't all classes have this method?

Yes, including String. That much is the same as Java.
I thought "new" created a new object on the heap.

Not always.
That is how it works in Java. What object is being created with a
primitive?

Well, the *value* being created is a new value type value, in this case
0. If it's a local variable, that value will be on the stack.

The reason it's useful in C# is that you can create your own value
types, and it often makes sense for them to have constructors (quite
apart from the parameterless one which is half there, half not - it
depends on whether you're talking in C# terms or .NET terms).
 
?

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

Dom said:
Sorry, I meant String.ToString(). Don't all classes have this method?

Yes. But it is not static, so you need an instance of String.
I thought "new" created a new object on the heap. That is how it
works in Java. What object is being created with a primitive?

In C# you can also use new on structs (and therefore simple types
as well).

int i = new int();

does the same thing as:

int i = 0;
BTW, did you used to post on a VAX/VMS newsgroup?

Yes.

Actually still do occasionally !

Arne
 
D

Dom

BTW, did you used to post on a VAX/VMS newsgroup?
Yes.

Actually still do occasionally !

Well, hi there Arne! Small world, isn't it? I remember you helped me
out on some fine points about sys$Get_VM maybe 20 years ago, and here
you are, telling me the difference between String and string!

I may need your help again sometime around April 2027 !

Dom
 
?

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

Dom said:
Well, hi there Arne! Small world, isn't it? I remember you helped me
out on some fine points about sys$Get_VM maybe 20 years ago, and here
you are, telling me the difference between String and string!

I may need your help again sometime around April 2027 !

If I can search Google groups correct then it was in October 2000.

So only 7 years.

BTW, I think there are a few c.o.v'ers here.

Arne
 

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