Get the first and last item of an array of strings

后端 未结 5 1086
既然无缘
既然无缘 2021-02-05 06:35

If I have the following array of strings:

string[] stringArray = {\"one\", \"two\", \"three\", \"four\"};

Is there a way to get the first and l

5条回答
  •  遇见更好的自我
    2021-02-05 07:33

    Use LINQ First() and Last() methods.

    Moreover, both methods have useful overload which allows specifying boolean condition for elements to be considered as first or last.

提交回复
热议问题