ย้อนกลับองค์ประกอบในอาร์เรย์โดยใช้วิธีการย้อนกลับ
นี่คืออาร์เรย์อักขระของเรา
char[] ch = { 't', 'i', 'm', 'e' }; ตอนนี้ใช้เมธอด Reverse() กับวิธี AsQueryable() เพื่อรับการย้อนกลับ
ch.AsQueryable().Reverse();
ให้เราดูรหัสที่สมบูรณ์
ตัวอย่าง
using System;
using System.Linq;
using System.Collections.Generic;
public class Demo {
public static void Main() {
char[] ch = { 't', 'i', 'm', 'e' };
Console.Write("String = ");
foreach(char arr in ch) {
Console.Write(arr);
}
IQueryable<char> res = ch.AsQueryable().Reverse();
Console.Write("\nReversed String = ");
foreach (char c in res) {
Console.Write(c);
}
}
} ผลลัพธ์
String = time Reversed String = emit