63 034
Assignments Done
99,1%
Successfully Done
In July 2018

Answer to Question #7794 in C# for Shridhar Iyer

Question #7794
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
Expert's answer
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();
}
}
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be first!

Leave a comment

Ask Your question

Submit
Privacy policy Terms and Conditions