Force function to return value and make compile error C#

后端 未结 4 1096
爱一瞬间的悲伤
爱一瞬间的悲伤 2021-01-18 06:23

I have a class and a method within that class. However this class method returns a string. When I call the class method I don\'t get an error even though I\'m not catching

4条回答
  •  忘掉有多难
    2021-01-18 06:36

    In a word, no. Not by force as such.

    It's commonplace to not capture return values. Examples in the core libs abound (adding elements to a Hashset for example, the function actually returns a bool to flag whether it was actually added or if it already existed - depending on individual implementation I may or may not care about that).

    Of course, you can always just do something like string str = MyFunction() each time then never use str but I guess you probably already knew that.

提交回复
热议问题