error when passing a reference to a derived object in a method

前端 未结 3 608
我寻月下人不归
我寻月下人不归 2020-12-07 02:59

In c# I am trying to implement a method which I can use to bind data to any control I pass to it (provided of course the control is derived from a databoundcontrol object)

3条回答
  •  时光取名叫无心
    2020-12-07 03:45

    Andrew Hare is correct, but in this case, you may not even want to be using the ref. Objects in C# are already passed by reference*. (As opposed to value types, which are not passed by reference unless you use the ref keyword.) There are very few cases that I can think of where you'd actually need to pass a reference type in that way. Without the ref, your original code should work just fine.

    **Not really, but it's easier to understand that way if you come from a non-C# background. The reference is actually passed by value. There is an excellent article on the exactly how this all works.*

提交回复
热议问题