C# Pointers in a Method's arguments?

后端 未结 5 2051
一个人的身影
一个人的身影 2021-01-11 22:24

I wish to directly modify a variable\'s value outside of a method from inside it.
Pointers are the way, correct?

How?

5条回答
  •  佛祖请我去吃肉
    2021-01-11 22:42

    If the value is a class, than it is already passed by reference, and nothing else is required, unless you need to assign the object to something, val = anotherobject, then you need to use the ref or out keywords.

    If it is a struct (int, float, long, double, etc), then you must use ref (if the object may or may not be changed) or out (if the object will be changed). You can have more than one argument in a method marked by ref or val.

提交回复
热议问题