Re: Passing in SqlConnection by ref
From: Jon Skeet [C# MVP] (skeet_at_pobox.com)
Date: 02/13/05
- Next message: LP: "What's the best way to insert new records only"
- Previous message: Sahil Malik: "Re: Update dataset/datatable disconnected?"
- In reply to: LP: "Re: Passing in SqlConnection by ref"
- Next in thread: Craig Wagner: "Re: Passing in SqlConnection by ref"
- Messages sorted by: [ date ] [ thread ]
Date: Sun, 13 Feb 2005 19:16:51 -0000
LP <lp@a.com> wrote:
> Craig, Now, that's what I call a good explanation. Thanks a lot.
>
> My concern was if I pass in connection to another method, I wanted to make
> sure that both objects will be working with same instance of connection
> object. So it can closed/disposed in one place. I thought I needed to pass
> it in with "ref" to accomplish that.
> From what you're saying as long as I don't create a new instance in a
> receiving method, it will be the same instance of conn object, since it's a
> reference type. So "ref" is not really required, though it would more or
> less do the same thing (it's a true pointer as oppose to reference type).
> Please let me know if my interpretations are correct.
That sounds about right. Don't use ref unless you need to though - it
would suggest to someone reading the code that you were going to change
the value of the variable within the method.
-- Jon Skeet - <skeet@pobox.com> http://www.pobox.com/~skeet If replying to the group, please do not mail me too
- Next message: LP: "What's the best way to insert new records only"
- Previous message: Sahil Malik: "Re: Update dataset/datatable disconnected?"
- In reply to: LP: "Re: Passing in SqlConnection by ref"
- Next in thread: Craig Wagner: "Re: Passing in SqlConnection by ref"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|