Re: Best Practices: always use new() with objects?
- From: raylopez99 <raylopez99@xxxxxxxxx>
- Date: Sun, 12 Aug 2007 13:39:28 -0700
On Aug 12, 6:44 am, GlennDoten <gdo...@xxxxxxxxx> wrote:
I kinda have a feeling you are trying to ask a different question here,
or I have misinterpreted what you are asking.
--
-glenn-
No, you answered my question glenn.
But I posted this before I realized that in C# there is never any
implicit shallow copying (unlike C++), therefore, SomeClass X = Y; is
somewhat pointless, since you can use Y instead in the body of the
function. However, as I type this I realize that if you pass by value
rather than by reference, that is, if you do NOT use the 'ref'
keyword: void somemethod(ref SomeClass Y) // i.e. DON'T do this, but
rather, as in your example, void somemethod(SomeClass Y), then you can
use SomeClass X = Y; for code clarity, if you do stuff in the method
that returns SomeClass (to give a reader of your code some idea that
you're not returning Y as modified, but X, though one can argue that
the lack of the 'ref' keyword should clue in the reader that this is
the case.
Come to think of it, now that I see C# is like old-fashioned C in that
you are keeping track of passing a pointer (or reference) around, why
would you ever use SomeClass X = Y; ? Just use Y directly in your
method. All this time in C# I've been doing either "FIRST WAY" or,
(rarely, but in a few instances) "SECOND WAY" above, and this has
needlessly been somewhat slowing down my programs, though how much is
debatable with all the stuff going on behind the scenes in C#.NET
anyway.
RL
.
- Follow-Ups:
- Re: Best Practices: always use new() with objects?
- From: Peter Duniho
- Re: Best Practices: always use new() with objects?
- From: Göran Andersson
- Re: Best Practices: always use new() with objects?
- References:
- Best Practices: always use new() with objects?
- From: raylopez99
- Re: Best Practices: always use new() with objects?
- From: GlennDoten
- Best Practices: always use new() with objects?
- Prev by Date: Re: More than a style issue?
- Next by Date: Re: More than a style issue?
- Previous by thread: Re: Best Practices: always use new() with objects?
- Next by thread: Re: Best Practices: always use new() with objects?
- Index(es):
Relevant Pages
|