次の方法で共有


コンパイラ エラー CS1716

更新 : 2007 年 11 月

エラー メッセージ

'System.Runtime.CompilerServices.FixedBuffer' 属性を使用しません。'fixed' フィールド修飾子を使用してください。

このエラーは、フィールド宣言など、固定サイズの配列宣言が記述されたアンセーフ コード セクションで発生します。この属性は使用しないでください。代わりに、fixed キーワードを使用します。

使用例

次の例では CS1716 エラーが生成されます。

// CS1716.cs
// compile with: /unsafe
using System;
using System.Runtime.CompilerServices;

public struct UnsafeStruct
{
    [FixedBuffer(typeof(int), 4)]  // CS1716
    unsafe public int aField;
    // Use this single line instead of the above two lines.
    // unsafe public fixed int aField[4];
}

public class TestUnsafe
{
    static int Main()
    {
        UnsafeStruct us = new UnsafeStruct();
        unsafe
        {
            if (us.aField[0] == 0)
                return us.aField[1];
            else
                return us.aField[2];
        }
    }
}