<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                ThinkChat2.0新版上線,更智能更精彩,支持會話、畫圖、視頻、閱讀、搜索等,送10W Token,即刻開啟你的AI之旅 廣告
                # Compiler Error CS1656 無法給“variable”賦值,因為它是“read-only variable type” 當變量賦值發生在只讀上下文中時,將出現此錯誤。只讀上下文包括 [foreach](https://msdn.microsoft.com/zh-cn/library/ttw7t8t6.aspx) 迭代變量、[using](https://msdn.microsoft.com/zh-cn/library/yh598w02.aspx) 變量和 [fixed](https://msdn.microsoft.com/zh-cn/library/f58wzh21.aspx) 變量。若要解決此錯誤,請避免在 **using** 塊、**foreach** 語句和 **fixed** 語句中給變量賦值。 以下示例生成錯誤 CS1656,因為它嘗試替換 **foreach** 循環內的集合中的所有元素。解決此錯誤的一種方法是將 **foreach** 循環更改為 [for](https://msdn.microsoft.com/zh-cn/library/ch45axte.aspx) 循環。另一種方法(此處未顯示)是修改現有元素的成員;這可能對類起作用,但對結構不起作用。 ``` using System; using System.Collections; using System.Collections.Generic; using System.Text; namespace CS1656_2 { class Book { public string Title; public string Author; public double Price; public Book(string t, string a, double p) { Title=t; Author=a; Price=p; } } class Program { private List<Book> list; static void Main(string[] args) { Program prog = new Program(); prog.list = new List<Book>(); prog.list.Add(new Book ("The C# Programming Language", "Hejlsberg, Wiltamuth, Golde", 29.95)); prog.list.Add(new Book ("The C++ Programming Language", "Stroustrup", 29.95)); prog.list.Add(new Book ("The C Programming Language", "Kernighan, Ritchie", 29.95)); foreach(Book b in prog.list) { // Cannot modify an entire element in a foreach loop // even with reference types. // Use a for or while loop instead if (b.Title == "The C Programming Language") // Cannot assign to 'b' because it is a 'foreach // iteration variable' b = new Book("Programming Windows, 5th Ed.", "Petzold", 29.95); //CS1656 } //With a for loop you can modify elements //for(int x = 0; x < prog.list.Count; x++) //{ // if(prog.list[x].Title== "The C Programming Language") // prog.list[x] = new Book("Programming Windows, 5th Ed.", "Petzold", 29.95); //} //foreach(Book b in prog.list) // Console.WriteLine(b.Title); } } } ``` 下面的示例演示如何在除 **foreach** 循環之外的其他上下文中生成 CS1656: ``` // CS1656.cs // compile with: /unsafe using System; class C : IDisposable { public void Dispose() { } } class CMain { unsafe public static void Main() { using (C c = new C()) { // Cannot assign to 'c' because it is a 'using variable' c = new C(); // CS1656 } int[] ary = new int[] { 1, 2, 3, 4 }; fixed (int* p = ary) { // Cannot assign to 'p' because it is a 'fixed variable' p = null; // CS1656 } } } ```
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看