Argument 1 cannot convert from 'string' to 'int' in LIst in C#.NET


Error message:
Argument 1: cannot convert from 'string' to 'int' in LIst
Error Description:

using System;
using System.Collections.Generic;

namespace ConsoleApp1
{
    class Program
    {
        static void Main(string[] args)
        {
            List<int> objList = new List<int>();
            objList.Add("Surya Infoware");
        }
    }
}

Error Solution:
using System;
using System.Collections.Generic;

namespace ConsoleApp1
{
    class Program
    {
        static void Main(string[] args)
        {
            List<int> objList = new List<int>();
            objList.Add(5);
            Console.WriteLine("List value:"+objList[0].ToString());
            Console.Read();
        }
    }
}

Output:




Share this post :

Post a comment

Please share your valuable feedback and share this article in social media.

 
Support : Ranga Rajesh Kumar
Copyright © 2019. Error Solution - All Rights Reserved
Site Designed by Ranga Rajesh Kumar