Hi,
this is for a project. i have to make a console application and need to work with a List<String> to hole values for the lifetime of the console application. I have initialised it in the class with the declaration "List<String> myList = new List<String>". this is done at the constructor level and when i need to use it in a method or pass it to another method of another class and use it there, it is not initialised and is null and as a result, any add gives me an error. please help me as i need a solution to it in the next hour or so or my assignment would be screwed. Please help soon. appreciate it. Thanks and Regards
1
Expert's answer
2012-03-29T11:13:42-0400
using System; using System.Collections.Generic; using System.Linq; using System.Text;
namespace Question7794 { public class TestString{ public List<string> myList; //Constructor public TestString() { myList = new List<string>(); } } class Program { private static TestString TestString=new TestString(); static void Main(string[] args) { TestString.myList.Add("Test string"); Console.WriteLine(TestString.myList[0].ToString()); Console.ReadLine(); } } }
Numbers and figures are an essential part of our world, necessary for almost everything we do every day. As important…
APPROVED BY CLIENTS
"assignmentexpert.com" is professional group of people in Math subjects! They did assignments in very high level of mathematical modelling in the best quality. Thanks a lot
Comments
Leave a comment