Answers for "csharp get first element of list"

C#
1

c# select first value from list

lstComp.First();
//You can also use FirstOrDefault() just in case lstComp does not contain any items.

//To get the Component Value:
var firstElement = lstComp.First().ComponentValue("Dep");

//This would assume there is an element in lstComp. An alternative and safer way would be...
var firstOrDefault = lstComp.FirstOrDefault();
if (firstOrDefault != null) 
{
    var firstComponentValue = firstOrDefault.ComponentValue("Dep");
}
Posted by: Guest on March-03-2020
0

csharp get first element of list

using System;

using System.Linq;

 

namespace LINQExamples

{

class Program

{

static void Main(string[] args)

{

int[] objList = { 1, 2, 3, 4, 5 };

int result = objList.First();

Console.WriteLine("Element from the List: {0}", result);

Console.ReadLine();

}

}

}
Posted by: Guest on October-04-2021
0

csharp first element of array

using System;

namespace InitArray
{
    class Program
    {
        static void Main(string[] args)
        {
            int[] array = new int[5];

            array[0] = 1;
            array[1] = 2;
            array[2] = 3;
            array[3] = 4;
            array[4] = 5;
            
            for (int i = 0; i < array.Length; i++) 
            {
                Console.WriteLine(array[i]);
            }  
        }
    }
}
Posted by: Guest on March-18-2020

Code answers related to "csharp get first element of list"

C# Answers by Framework

Browse Popular Code Answers by Language