title: Trying to understand Data transfer in byte[] Array C#
body: <p>First I would like to say that I tried to do research on how to understand what I'm about to ask but just couldn't come up with what I was looking for.  This being said I thought I would ask some of you crazy smart people to explain this in lamens terms for me as best as possible.</p>
  
  <p>My issue is that I have a perfectly good "Copy Pasted" code to download a file using ftpWebRequest.  I will paste the code below:</p>
  
  <pre><code>        public static void DownloadFiles()
      {
          FtpWebRequest request = (FtpWebRequest)WebRequest.Create("ftp://****/test.zip");
          request.Credentials = new NetworkCredential("****", "*****");
          request.UseBinary = true; 
          request.Method = WebRequestMethods.Ftp.DownloadFile;
  
          FtpWebResponse response = (FtpWebResponse)request.GetResponse();
          Stream responseStream = response.GetResponseStream();
          FileStream writer = new FileStream("***/test.zip", FileMode.Create);
  
          int bufferSize = 2048;
          int readCount;
          byte[] buffer = new byte[2048];
  
          readCount = responseStream.Read(buffer, 0, bufferSize);
  
          while (readCount &gt; 0)
          {
              writer.Write(buffer, 0, readCount);                
              readCount = responseStream.Read(buffer, 0, bufferSize);                
          }
  
          responseStream.Close();
          response.Close();
          writer.Close();
      }
  </code></pre>
  
  <p>Like I said this works perfectly and downloads the zip file without any issues.  What I'm trying to understand because I think "Copy Paste" code is a horrible idea is how this is actually functinning.  The only part that I do not understand is what is actually happening between these points:</p>
  
  <pre><code>            int bufferSize = 2048;
          int readCount;
          byte[] buffer = new byte[2048];
  
          readCount = responseStream.Read(buffer, 0, bufferSize);
  
          while (readCount &gt; 0)
          {
              writer.Write(buffer, 0, readCount);                
              readCount = responseStream.Read(buffer, 0, bufferSize);                
          }
  </code></pre>
  
  <p>If someone would be so kind to please explain what is actually happening in the buffer, why we set it to 2048 and what the while loop is actually doing would be very appreciated.  Just as a side not I have gone through the code and put message boxes and other debug's in to try and understand whats going on but without success.  Thank you in advance and I apologize if this seems very elementary.</p>