0

Hi I have a few lines of code that checks if the element is in List

But when List becomes too bigit consumes too much RAM is ther any whay to imrove it so it consumese lesser RAM

List<string> list = File.ReadAllLines(path);
string user = dynamic;
if (list.Contains(user))
{
    return "go";
}
else
{
    return null;
}
Harardin
  • 55
  • 6
  • Yes. Use Stream to read file. And your question is related to _file reading_ to memory not a List itself. – Renatas M. Jul 31 '18 at 09:58
  • 1
    how about not reading all the lines at ones ? Have a look at `ReadLines` method. – Selman Genç Jul 31 '18 at 09:58
  • Need more information about the usecase here, is it a one-off check for 1 user type of thing, or do you check for many users against the same file, or ...? If it's a one-off thing you can do `File.ReadLines(path).Any(line => line == user)`. – Lasse V. Karlsen Jul 31 '18 at 09:58
  • What is consuming the RAM? The list itself? Or are you saying the search is time consuming? – doctorlove Jul 31 '18 at 09:58

0 Answers0