c# - Manipulate Referenced Object -
Is there any way that I can pass in the context of an object, manipulate it within my method which is straight Replaces the referenced object?
For example, I want to pass a dropdown list in my method, it should be manipulated and done. This method is being taken to any dropdown list:
public static void mismatched (dropdown list list 1, ref dropdown list list 2) {// just manipulating the dropdown here ... There is no need to come back just add or remove some values from the list 2}
Obviously I can not just pass the dropdownlist object to list2, how can I do this? I am going to delete some values in the list and it will be a good utility method, so I do not have to repeat this code everywhere for this functionality that I am performing in the law.
If you are manipulating the internal data of a single reference type, then you have some special Do not want. When passing an object there is a reference type for a method that you do not copy, instead you pass the context of the object, controlling this context will change the original thing.
Invalid MyMthi (list & lt; string & gt; list) {list.Add ("foo"); } Zero Example () {List & lt; String & gt; L = new list & lt; Sting & gt; (); MyMethod (L); Console.WriteLine (l.Count); // Print 1Mytham (L); Console.WriteLine (l.Count); // print2}
Now if you want to point in the original context, you will need a ref moderator.
Comments
Post a Comment