Re: FAQ Suggestions
From: Nick Malik (nickmalik_at_hotmail.nospam.com)
Date: 02/24/04
- Next message: Stoitcho Goutsev \(100\) [C# MVP]: "Re: How do you pronounce it?"
- Previous message: bob: "No .NET framework"
- In reply to: Jon Skeet [C# MVP]: "Re: FAQ Suggestions"
- Next in thread: Jon Skeet [C# MVP]: "Re: FAQ Suggestions"
- Reply: Jon Skeet [C# MVP]: "Re: FAQ Suggestions"
- Messages sorted by: [ date ] [ thread ]
Date: Tue, 24 Feb 2004 15:39:47 GMT
Hello Jon and Richard,
I wasn't aware of your effort.
Have you thought of allowing your FAQs to be compiled on a Wiki server?
In my mind, the advantage would be that the FAQs can be honed by the
community (or the MVP) on an ongoing basis, not just a one-off effort.
Either way, it's a valuable effort. Thanks for doing this work.
--- Nick
"Jon Skeet [C# MVP]" <skeet@pobox.com> wrote in message
news:MPG.1aa3d029bf928a5698a1d2@msnews.microsoft.com...
> Richard A. Lowe <chadich@yumspamyumYahoo.com> wrote:
> > Hi, here are answers for some of the questions I suggested a short time
ago
> > for the m.p.d.l.c FAQ Jon Skeet is organizing. It was Jon's intention
that
> > these be 'honed' by the group before being included - so hone away.
It's my
> > intention that you merely not 'tear me a new one' for any inaccuracies
in my
> > answers. I give credit to Anders Hejlsberg for answering my question
about
> > the non-int operators a short while ago in this thread (which is the
basis
> > for my answer below):
>
> Great stuff - thanks very much for all your work! A few comments (with
> questions without any comments snipped).
>
> > - why are struct constructors in C# required to have at least one
argument?
> > (C# as a language)
> >
> > The .NET runtime can't guarantee that parameterless constructors will be
> > called. If structs where to allow default, parameterless constructors,
it
> > would imply that these default constructors would *always* be called.
>
> I'm going to try to steer clear of using "default" for parameters
> unless I'm talking about the constructor supplied by default if you
> don't give one (in a reference type). I believe "parameterless" is
> actually the correct term - for instance, you can't supply a default
> constructor for a reference type, you just get given one if you don't
> supply any constructors at all. This is one piece of terminology which
> is much abused (including by Microsoft), but I believe the difference
> can be useful, so I'll try to draw a distinction.
>
> On the other hand, I've just looked at the CLR spec and that mentions
> default constructors 3 times, so maybe I'm just wrong. Shame though, I
> thought it was quite handy...
>
> > However, the runtime can not make this guarantee. For example an array
of
> > value types will be initialized to the initial values of it's members
(i.e.
> > 0 for number type primitive members, null for reference types etc) *NOT
to
> > the values provided in a default constructor* - which makes structs
better
> > performing by not having to call constructor code. Enforcing a minimum
of
> > one parameter in the constructor reduces the possibility that someone
will
> > define a constructor that they then expect to be called every time one
of
> > their struct types is constructed.
>
> Explaining here that CLR types *can* have parameterless constructors,
> but C# can't generate such types would be a good idea. It took me a
> while to work out what was meant here.
>
> > - why does C# return an int when you add two bytes/shorts/sbytes/ushorts
> > together?
> >
> > C# always promotes 8 and 16 bit values to 32 bits before performing
> > arithmetic operations. It is actually less efficient to emulate 8 or 16
bit
> > arithmetic on a 32 bit processor than it is to just do the operations in
32
> > bits.
> >
> > C# narrowing conversions (conversions that might affect the magnitude of
a
> > number like casting an int to short) are always explicit. By contrast
they
> > can occur implicitly in C/C++. That's why you have to cast the result of
> > expressions like ushort + ushort back to ushort in an assignment.
>
> I would personally stick to short in the example here, just so people
> don't think it's got *anything* to do with being unsigned!
>
> > - How can I implement a *global* hook in C#?
> >
> > It is not possible because C# / .NET does not support an essential
element:
> > a DLL export providing a consistent function pointer. See here
> > http://support.microsoft.com/?kbid=318804 at the bottom for a little
more
> > detail.
>
> It might be worth making the question a bit more explicit in terms of
> what a global hook is, just for clarity. (Or put it in the answer.)
>
> > - How do I tell C# what kind of literal number I want? (f, L, U etc) (C#
as
> >
> > If you need to tell C# that you want it to treat a literal as a
particular
> > type of number, you may do so by adding a number type suffix at the end
of
> > the literal you provide:
> >
> > 1U; // an unsiged int
> > 1ul; // an unsigned long
> > 1f; // a System.Single floating-point number;
>
> Add
> 1d // a System.Double floating-point number
> 1m // a System.Decimal floating-point number
>
> Then at least even if there aren't all the variants in terms of case,
> all the bases are covered, as it were.
>
> > This is somewhat important because sometimes you must match a literal to
the
> > signature of something or specify the value to 'defeat' an implicit cast
> > behavior you don't like. For example this:
> > Hashtable names = new Hashtable(100, 0.1);
> > won't compile because it takes the signatures (int, float) and the above
is
> > (int, double). The line should read:
> > Hashtable names = new Hashtable(100, 0.1f);
> >
> > A full listing of the suffixes is in the Grammar portion of the c#
> > specification under C.1.8 Literals.
> > http://msdn.microsoft.com/library/default.asp?url=/library/en-us/csspe
> > c/html/vclrfcsharpspec_C.asp
>
> Unless anyone particularly minds, I'd like to keep to the ECMA spec
> rather than the MS spec for references. This may be impossible for 2.0
> features for a while, but the FAQ can be fixed later for those features
> :)
>
> > - What's the difference between the ref and out modifiers on parameters?
> >
> > Both the ref and out method parameters are applied to arguments of a
method
> > and both mean that the argument will be passed "by reference" (either a
> > value type variable by reference or a reference type variable by
reference).
> > The out parameter, however, allows you to pass in an uninitialized
variable
> > like so and guarantees it will come back with it's value set (so long as
the
> > called method was written in C#, anyway).
> >
> > int i;
> > DoStuffByRef(out i);
> > // i is now a usable int value
>
> Gosh, I'm surprised I don't have that in there already. I'll include a
> link to my page about parameter passing...
>
> --
> Jon Skeet - <skeet@pobox.com>
> http://www.pobox.com/~skeet
> If replying to the group, please do not mail me too
- Next message: Stoitcho Goutsev \(100\) [C# MVP]: "Re: How do you pronounce it?"
- Previous message: bob: "No .NET framework"
- In reply to: Jon Skeet [C# MVP]: "Re: FAQ Suggestions"
- Next in thread: Jon Skeet [C# MVP]: "Re: FAQ Suggestions"
- Reply: Jon Skeet [C# MVP]: "Re: FAQ Suggestions"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|