title: How to write array of struct with foreach in C#
body: <p>In here I can't use <code>foreach</code>:</p>
  
  <blockquote>
    <p>`Error    CS0030  Cannot convert type 'ConsoleApplication5._3.Struct.Sach' to 'int'</p>
  </blockquote>
  
  <p>How can I fix it?</p>
  
  <pre><code>public struct Sach
  {
      public string TenSach;
      public string TacGia;
      public string GioiThieu;
      public int ID;
      public void nhapdulieu(string q,string w, string e, int r)
      {
          TenSach = q;
          TacGia = w;
          GioiThieu = e;
          ID = r;
      }
      public void Insach()
      {
          Console.Write($"Ten sach: {TenSach}\n");
          Console.Write($"Tac gia: {TacGia}\n");
          Console.Write($"Gioi thieu: {GioiThieu}\n");
          Console.Write($"Ma sach: {ID}\n");
      }
  };
  
  
  public class QuanLySach
  {
      public static void NhapSach()
      {
  
          Sach[] sach1 = new Sach[4];
          for(int i=0;i&lt;4;i++)
          {
              Console.WriteLine("nhap ten sach, tac gia, gioi thieu, id:");
              sach1[i].TenSach = Console.ReadLine();
              sach1[i].TacGia = Console.ReadLine();
              sach1[i].GioiThieu = Console.ReadLine();
              var vv = Console.ReadLine();
              Int32.TryParse(vv, out sach1[i].ID);
          }
  
          foreach(int bb in sach1)
          {
           // in here i cant use foreach but i dont know why?
          }
          Console.ReadLine();
      }  
      }
  }
  </code></pre>