C# 程式以顯示第一個陣列元素


以下是我們的陣列 −

double[] myArr = {20.5, 35.6, 45.7, 55.6, 79.7};

要獲取第一個元素,請使用 First() 方法。

myArr.AsQueryable().First();

讓我們來看看完整的程式碼 −

示例

 線上試用

using System;
using System.Linq;
using System.Collections.Generic;
class Demo {
   static void Main() {
      double[] myArr = {20.5, 35.6, 45.7, 55.6, 79.7};
      double res = myArr.AsQueryable().First();
      Console.WriteLine(res);
   }
}

輸出

20.5

更新於: 23-6-2020

2K+ 檢視

開啟你 職業生涯

透過完成課程獲得認證

開始
廣告
© . All rights reserved.