c# Casting v As operator
-
Possibly a font-problem on your end? It looks roughly like: W**.'.** Balboos - the three punctuation-like characters being the HTML character code:
& there4;
(space put in after & so it doesn't render)"The difference between genius and stupidity is that genius has its limits." - Albert Einstein
"As far as we know, our computer has never had an undetected error." - Weisert
"If you are searching for perfection in others, then you seek disappointment. If you are seek perfection in yourself, then you will find failure." - Balboos HaGadol Mar 2010
Not your name, your sig:
W∴ Balboos wrote:
Possibly a font-problem on your end?
It looks roughly like: W**.'.** Balboos - the three punctuation-like characters being the HTML character code:& there4;
(space put in after & so it doesn't render)"The difference between genius and stupidity is that genius has its limits." - Albert Einstein
"As far as we know, our computer has never had an undetected error." - Weisert
"If you are searching for perfection in others, then you seek disappointment. If you are seek perfection in yourself, then you will find failure." - Balboos HaGadol Mar 2010
There's a lot of white space...
Panic, Chaos, Destruction. My work here is done. Drink. Get drunk. Fall over - P O'H OK, I will win to day or my name isn't Ethel Crudacre! - DD Ethel Crudacre I cannot live by bread alone. Bacon and ketchup are needed as well. - Trollslayer Have a bit more patience with newbies. Of course some of them act dumb - they're often *students*, for heaven's sake - Terry Pratchett
-
It's a debate, not a question.
www.software-kinetics.co.uk Wear a hard hat it's under construction
To be or not to be.? That is a question. :-D
Panic, Chaos, Destruction. My work here is done. Drink. Get drunk. Fall over - P O'H OK, I will win to day or my name isn't Ethel Crudacre! - DD Ethel Crudacre I cannot live by bread alone. Bacon and ketchup are needed as well. - Trollslayer Have a bit more patience with newbies. Of course some of them act dumb - they're often *students*, for heaven's sake - Terry Pratchett
-
To be or not to be.? That is a question. :-D
Panic, Chaos, Destruction. My work here is done. Drink. Get drunk. Fall over - P O'H OK, I will win to day or my name isn't Ethel Crudacre! - DD Ethel Crudacre I cannot live by bread alone. Bacon and ketchup are needed as well. - Trollslayer Have a bit more patience with newbies. Of course some of them act dumb - they're often *students*, for heaven's sake - Terry Pratchett
Nope wrong, you've omitted the ? mark. ;)
www.software-kinetics.co.uk Wear a hard hat it's under construction
-
Nope wrong, you've omitted the ? mark. ;)
www.software-kinetics.co.uk Wear a hard hat it's under construction
Did I?
Panic, Chaos, Destruction. My work here is done. Drink. Get drunk. Fall over - P O'H OK, I will win to day or my name isn't Ethel Crudacre! - DD Ethel Crudacre I cannot live by bread alone. Bacon and ketchup are needed as well. - Trollslayer Have a bit more patience with newbies. Of course some of them act dumb - they're often *students*, for heaven's sake - Terry Pratchett
-
Did I?
Panic, Chaos, Destruction. My work here is done. Drink. Get drunk. Fall over - P O'H OK, I will win to day or my name isn't Ethel Crudacre! - DD Ethel Crudacre I cannot live by bread alone. Bacon and ketchup are needed as well. - Trollslayer Have a bit more patience with newbies. Of course some of them act dumb - they're often *students*, for heaven's sake - Terry Pratchett
The hand is quicker than the I eye.
www.software-kinetics.co.uk Wear a hard hat it's under construction
-
a. Throw back from C++ programming.
www.software-kinetics.co.uk Wear a hard hat it's under construction
Wrong - a is C-style casting, not C++
-
Wrong - a is C-style casting, not C++
Splitting hairs :)
www.software-kinetics.co.uk Wear a hard hat it's under construction
-
Norm .net wrote:
Good point.
Holy cr_p! I'm going to the pub, we'll see what comes out after lunch! :laugh:
Panic, Chaos, Destruction. My work here is done. Drink. Get drunk. Fall over - P O'H OK, I will win to day or my name isn't Ethel Crudacre! - DD Ethel Crudacre I cannot live by bread alone. Bacon and ketchup are needed as well. - Trollslayer Have a bit more patience with newbies. Of course some of them act dumb - they're often *students*, for heaven's sake - Terry Pratchett
:beer:
www.software-kinetics.co.uk Wear a hard hat it's under construction
-
Which is exactly why this is more of a programming question than a "lifestyle choice" question.
I'd say more of a debate, but as we all know rules of the lounge, I'd say just go along with it and chill :)
www.software-kinetics.co.uk Wear a hard hat it's under construction
-
True, but you should know beforehand if the casting is correct.
www.software-kinetics.co.uk Wear a hard hat it's under construction
If you do know something is not gonna be null, the cast is more efficient.
-
For those using c#, what do you prefer? A.
SomeObject obj = (SomeObject) e;
or B.
SomeObject obj = e as SomeObject;
www.software-kinetics.co.uk Wear a hard hat it's under construction
The second one sounds like some kind of hominid comrade Norm.
Und wenn du lange in einen abgrund blickst, blickt der Abgrund auch in dich hinein.
-
If you do know something is not gonna be null, the cast is more efficient.
To add... and the cast is a qualified cast.
www.software-kinetics.co.uk Wear a hard hat it's under construction
-
The second one sounds like some kind of hominid comrade Norm.
Und wenn du lange in einen abgrund blickst, blickt der Abgrund auch in dich hinein.
Don't fancy seeing your code if you think b. looks like a great ape :rolleyes:
www.software-kinetics.co.uk Wear a hard hat it's under construction
-
For those using c#, what do you prefer? A.
SomeObject obj = (SomeObject) e;
or B.
SomeObject obj = e as SomeObject;
www.software-kinetics.co.uk Wear a hard hat it's under construction
B. I don't like to rely on exceptions for normal processing (they are slow and clumsy for that), so you have to check for null.
SomeObject obj = e as SomeObject;
if (obj != null)
{
...
}While
if (e != null && e is SomeObject)
{
SomeObject obj = (SomeObject) e;
...
}looks ugly. Plus, if you are going to use
obj
as aSomeObject
instance, then the former is quicker since there is only one check on the type ofe
Real men don't use instructions. They are only the manufacturers opinion on how to put the thing together. Manfred R. Bihy: "Looks as if OP is learning resistant."
-
It depends. (A) will throw if the cast fails while (B) will evaluate to
null
if the cast fails. I use both depending on how I intend to handle the casting failure. /raviMy new year resolution: 2048 x 1536 Home | Articles | My .NET bits | Freeware ravib(at)ravib(dot)com
-
Not your name, your sig:
W∴ Balboos wrote:
Possibly a font-problem on your end?
It looks roughly like: W**.'.** Balboos - the three punctuation-like characters being the HTML character code:& there4;
(space put in after & so it doesn't render)"The difference between genius and stupidity is that genius has its limits." - Albert Einstein
"As far as we know, our computer has never had an undetected error." - Weisert
"If you are searching for perfection in others, then you seek disappointment. If you are seek perfection in yourself, then you will find failure." - Balboos HaGadol Mar 2010
There's a lot of white space...
Panic, Chaos, Destruction. My work here is done. Drink. Get drunk. Fall over - P O'H OK, I will win to day or my name isn't Ethel Crudacre! - DD Ethel Crudacre I cannot live by bread alone. Bacon and ketchup are needed as well. - Trollslayer Have a bit more patience with newbies. Of course some of them act dumb - they're often *students*, for heaven's sake - Terry Pratchett
He's doin it on purpose to annoy you Senhor Vilmos. I thought you would have figured that out by now :D
Und wenn du lange in einen abgrund blickst, blickt der Abgrund auch in dich hinein.
-
For those using c#, what do you prefer? A.
SomeObject obj = (SomeObject) e;
or B.
SomeObject obj = e as SomeObject;
www.software-kinetics.co.uk Wear a hard hat it's under construction
It is not about preference. When I want an exception in case of type error I use A., and if I want a null I use B. I don't see a point of something like:
SomeObj obj = e as SomeObject;
if (obj == null)
throw new InvalidCastException();Of course, in good languages casting is almost always a sign of a design error.
-
If an illegal cast is an exceptional (woah, that should never happen) situation, then (a) If there's a possibility that through normal use the cast might be invalid (e.g. Plug-in tpye code), then (b), followed by an If to check for Null. -Richard
Hit any user to continue.
Richard A. Dalton wrote:
Plug-in tpye code
I don't have such problems with plug-ins.
-
B. I don't like to rely on exceptions for normal processing (they are slow and clumsy for that), so you have to check for null.
SomeObject obj = e as SomeObject;
if (obj != null)
{
...
}While
if (e != null && e is SomeObject)
{
SomeObject obj = (SomeObject) e;
...
}looks ugly. Plus, if you are going to use
obj
as aSomeObject
instance, then the former is quicker since there is only one check on the type ofe
Real men don't use instructions. They are only the manufacturers opinion on how to put the thing together. Manfred R. Bihy: "Looks as if OP is learning resistant."
OriginalGriff wrote:
(they are slow and clumsy for that
No they're not.
-
For those using c#, what do you prefer? A.
SomeObject obj = (SomeObject) e;
or B.
SomeObject obj = e as SomeObject;
www.software-kinetics.co.uk Wear a hard hat it's under construction
I used to use A (C upbringing) now I kinda favor B.
I Haven't Gone To Bed With Any Ugly Women, but I've Sure Woke Up With A Few.