Re: C# 3.0 Proposals



Demetri,

See inline:

So then what is wrong with boxing using the object type. I'm assuming this
"implicit" typing is there to allow one to assign a type that is not known
during design time?

Isn't var x = 1; essentially the same as object x = 1; ?

The compiler has to know the type at compile time. When you use object,
it will box, but it will not box with var. Rather, that x is an int, and
you can not assign anything else to it.

Implicit means that it is assumed what the type is, not that it can hold
any type.

Just like you can do this:

double d = 10;

10 is technically an integer, but it is implicitly cast to a double.

In BOTH cases if I want to add another number to x then I must know before
hand that what i'm adding is of type int, correct?

Yes, you must, or have a type that is able to be implicitly cast to int.
The difference with:

object x = 1;

Is that you can then do:

x = "hey";

Whereas with var, you can't do it, you will get a compiler error.

You may argue, well you may not know that what you're adding is an int,
but
I argue that you will need to know somewhat in order to know that you CAN
add
the to mathematically.

There is no argument. With var, if you assign an int, it is an int, you
can't assign anything else to the variable. It is type-safe and the
compiler will verify that.

So i'm not sold on this var (implicit) typing thing. I certainly hope its
not a "workaround" to appease LINQ. Constructing a language to communicate
with one set of technolgies in mind is a bad plan in my estimation.

Actually, LINQ in itself doesn't communicate with one set of
technologies. It is DLINQ that does that. However, var is something that
is needed for LINQ to be utilized, yes.

Just try and compile this:

var x = 10;
x = "some string";

And then tell me how x is not type-safe. It might be ambiguous, but it
is definitely type-safe.


--
- Nicholas Paldino [.NET/C# MVP]
- mvp@xxxxxxxxxxxxxxxxxxxxxxxxxxx


--
-Demetri


"Nicholas Paldino [.NET/C# MVP]" wrote:

Demetri,

In reality, it is nothing like vb's variant type. For example, you
can
not do this:

var stringVariable = "hello there";
var numberVariable = 0;

// This line throws a compiler error.
numberVariable = stringVariable;

As you pointed out in the section that you copied and pasted, it is
an
^implicitly^ typed local variable. This doesn't mean that it is not
strong
typed, it just means that it is not explicitly typed, like so:

string stringVariable = "hello there";
int numberVariable = 0;

Hope this helps.


--
- Nicholas Paldino [.NET/C# MVP]
- mvp@xxxxxxxxxxxxxxxxxxxxxxxxxxx

"Demetri" <Demetri@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message
news:3CB651CD-6B01-4CBD-922B-3CF0306236A5@xxxxxxxxxxxxxxxx
Where can I go to state my views for or against some of the C# 3.0
proposals?

They are listed here:

http://download.microsoft.com/download/5/8/6/5868081c-68aa-40de-9a45-a3803d8134b8/CSharp_3.0_Specification.doc

For one thing, I can not believe they are trying to convert C# to VB by
making it a non-type safe language. For an example of what I mean read
this
excerpt from the doc:

"26.1 Implicitly typed local variables
In an implicitly typed local variable declaration, the type of the
local
variable being declared is inferred from the expression used to
initialize
the variable. When a local variable declaration specifies var as the
type
and
no type named var is in scope, the declaration is an implicitly typed
local
variable declaration. For example:

var i = 5;
var s = "Hello";
var d = 1.0;
var numbers = new int[] {1, 2, 3};
var orders = new Dictionary<int,Order>();"

I don't know about you guys, but that just smells too much like VB's
variant
type. NASTY!!

--
-Demetri





.



Relevant Pages

  • Re: C# 3.0 Proposals
    ... So i'm not sold on this var (implicit) typing thing. ... "26.1 Implicitly typed local variables ... In an implicitly typed local variable declaration, ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Delphi Type Narrowing
    ... > Easy enough mistake to transpose the two parameters - much harder to ... implicit typecast) to pass to the routine. ... Had the parameter been passed by reference (VAR) a compiler error ...
    (comp.lang.pascal.delphi.misc)
  • Re: C# 3.0 Proposals
    ... sound so much like VB's variant type. ... but it will not box with var. ... Implicit means that it is assumed what the type is, ... "26.1 Implicitly typed local variables ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Ada exception block does NOT work?
    ... The parameter/formal declarations are like ... the compiler would guess for you how to call puts. ... > * implicit declaration of external functions. ... > K&R probably where good assember programmers but they where lousy compiler ...
    (comp.lang.ada)
  • Re: trim(string) problems
    ... >> Together these make me think it is a compiler problem ... >> but correctly finds size with both explicit and implicit ... that makes my test program with the module work and should ...
    (comp.lang.fortran)