Monday, April 19, 2021

LINQ Array

Example - ASP.NET Core With LINQ Array
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

namespace LINQArray.Controllers
{
    public class HomeController : Controller
    {
        public async Task Index()
        {
            string[] names = new string[] { "Chandan", "Darsh", "Darpan", "Shiva", "Ajeet" };
            
            IEnumerable Names = from name in names select name;
            //IEnumerable Names = from name in names where name.Length == 5 select name;
            //IEnumerable Names = from name in names where name.Contains("an") select name;
            //IEnumerable Names = from name in names orderby name select name;
            //IEnumerable Names = from name in names orderby name descending select name;
            //IEnumerable Names = from name in names orderby name select name.ToUpper();
            
            foreach (var name in Names)
            {
                await Response.WriteAsync("<h1>" + name + "</h1>");
            }
            return string.Empty;
        }
    }
}
OUTPUT:


Updated on 6 July 2023

No comments:

Post a Comment

Hot Topics