Passing variable values between methods…?

前端 未结 3 1959
我在风中等你
我在风中等你 2021-01-28 09:08

Can someone help me with passing values from one class method to another in c#. I\'ve tried looking it up, but I get lost in pages of code and I cant find a simple example. Take

3条回答
  •  悲哀的现实
    2021-01-28 09:54

    Typically you would return the value from the function. You will want to think how your code calls different modules.

    You may find if the flow is complicated you may want to look in to inversion of control, although off topic and more advanced it is related to how code is chained together and that I feel is your underlying question/issue.

    If you had more than one value to return you could use a struct/class or mark parameters as ref allowing you to modify from within the function (variables passed by reference, as opposed to passing them by value which is done by default).

提交回复
热议问题