C-sharp beginners' questions about Index out of range

I am a beginner in C-sharp, and I recently encountered a problem. I don"t understand why I got this error
index was out of range.Must be non-negative and less than size of the collection
code as follows
class Program

{
    delegate bool Function(int a , int b);
    static Function b = delegate(int a ,int b){return a>=b;};
    static Function a = delegate(int a ,int b){return a<=b;};
    static List<int> Lis(List<int> nums , Function function)
    {
        var list = new List<int>();                        
        int maxOrMin  = list[0];
        foreach(int num in nums)
        {
            if(function(num,maxOrMin))
            {
                maxOrMin = num;
            }
        }
        list.Add(maxOrMin);
        return list;    
    }
    static void Main()
    {
        var list = Lis(new List<int> (){1,2,3,4,5,6} , b);
        foreach(var lis in list)
        {
            Console.WriteLine(lis);
        }
    }
}
Mar.04,2021

should be the problem here

var list = new List<int>();                        
int maxOrMin  = list[0];

the newly created List has a size of 0, while list [0] refers to the first element, which obviously does not exist

Menu