-2
\$\begingroup\$

I want to change the conversion from List<string> to the StringCollection type. To make files move faster.

try
{
    List<string> Picture = new List<string>();
    List<string> PaThS = new List<string>();
    string[] SVF =  {
                  Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData),  
                  Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData)
                    };
    foreach (var paths in SVF)
                PaThS.AddRange(Directory.GetDirectories(paths));

    foreach (var e in PaThS)
                Picture.AddRange(Directory.GetFiles(e, "*.jpg", SearchOption.AllDirectories));
}
catch{}
}

Actually by subject. Modify the StringCollection

\$\endgroup\$
  • \$\begingroup\$ You didn't learn anything from your last closed question. Have you actually read How do I ask a good question? I strongly doubt it. \$\endgroup\$ – t3chb0t Apr 15 '17 at 21:49
  • \$\begingroup\$ What are you trying to achieve with this code? Does it currently do what you expect it to? \$\endgroup\$ – holroy Apr 15 '17 at 21:56
  • \$\begingroup\$ I wrote in the title that I want to change the conversion from List <string> to the StringCollection type. To make files move faster. \$\endgroup\$ – GooliveR Apr 15 '17 at 21:58
  • \$\begingroup\$ @ArteS code review is for people to review your code for quality but not to fix your code. If you are having difficulty with the code, then post it on stackoverflow not here. \$\endgroup\$ – CodingYoshi Apr 15 '17 at 21:59
  • 1
    \$\begingroup\$ @ArteS "Modify the StringCollection" Demands like that never sound very good, neither are well achieved. You should consider to reformulate your question radically! \$\endgroup\$ – πάντα ῥεῖ Apr 16 '17 at 0:56
2
\$\begingroup\$

Hard disk accesses are measured in ms. RAM accesses in ns, i.e. they are roughly one million times faster! This means that List<string> manipulations (which happen in RAM) are much much faster than calls to Directory.GetDirectories or Directory.GetFiles that access the storage (hard disk, usb stick, SSD ...). Replacing List<string> by StringCollection won't make any difference!

List<string> and StringCollection both store data in the main memory. They don't move files and they don't search files.


It makes no sense to first add data to an array just to copy it to a list afterwards. Add it to the list directly with a collection initializer:

var paths = new List<string> {
    Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData),
    Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData)
};

What kind of crazy casing is PaThS? The usual C# style for variables is camelCase, i.e. the first character is lower case, succeeding words start with an upper-case letter.

\$\endgroup\$

Not the answer you're looking for? Browse other questions tagged or ask your own question.