Should I use “ref” to pass a list variable by reference to a method?
Is the answer that “ref” is not needed (as the list would be a reference variable), however for ease in readability put the “ref” in?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
No, don’t use a ref unless you want to change what list the variable is referencing. If you want to just access the list, do it without ref.
If you make a parameter ref, you are saying that the caller should expect that the parameter they pass in could be assigned to another object. If you aren’t doing that, then it’s not conveying the correct information. You should assume that all C# developers understand that an object reference is being passed in.