User Tools

Site Tools

blog:2021-04-13_c_dynamic_array_in_c



2021-04-13 C#: Dynamic Array in C#

  • 需要宣告不訂長度String Array
  • 將File讀入到一個字串陣列,以利後續操作
  • 避免直接Load到RichTextBox,造成Program Heavy Loading

My method

  •             // Load Log File
                var_LogFileContent = ""; // 
                string line;
                int counter = 0;
                //
                List<string> list = new List<string>();
                
                if (File.Exists(var_FileName))
                {
                    
                    // Read file 
                    // var_LogFileContent = File.ReadAllText(var_FileName);
                    System.IO.StreamReader file =
                    new System.IO.StreamReader(var_FileName);
                    while ((line = file.ReadLine()) != null)
                    {
                        // System.Console.WriteLine(line);
                        list.Add(line);
                        counter++;
                    }
    
                    file.Close();
                    //
                    var_LogStringArray = list.ToArray();
                    // richTextBox_LoadFile.Text = var_LogFileContent;
                }
                richTextBox_LoadFile.AppendText("Lines: " + counter.ToString() + "\n");

TAGS

  • 228 person(s) visited this page until now.

Permalink blog/2021-04-13_c_dynamic_array_in_c.txt · Last modified: 2021/04/13 17:24 by jethro

oeffentlich