Gets the attributes of the field reflected by the current instance.
A System.Reflection.FieldAttributes value that indicates the attributes of the field reflected by the current instance.
Operation
This property is read-only.Usage
Use this property to determine the accessibility of the field reflected by the current instance. Also use this property to determine if the field reflected by the current instance can be set after it is initialized, is implemented in native code, is a literal, or has a special name.
The following example demonstrates obtaining the attributes of two fields.
C# Example
using System; using System.Reflection; class MyClass { public int MyPublicInstanceField; private const int MyPrivateConstField = 10; } class FieldAttributesExample { public static void Main() { Type t = (typeof(MyClass)); string str; FieldInfo[] fiAry = t.GetFields( BindingFlags.Static | BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.DeclaredOnly ); foreach (FieldInfo fi in fiAry) { Console.WriteLine("Field {0} is: ", fi.Name); str = ((fi.Attributes & FieldAttributes.Static) != 0) ? "Static" : "Instance"; Console.Write(str + " "); str = ((fi.Attributes & FieldAttributes.Public) != 0) ? "Public" : "Not-Public"; Console.Write(str + " "); str = ((fi.Attributes & FieldAttributes.Literal) != 0) ? "Literal" : String.Empty; Console.WriteLine(str); } } }The output is
Field MyPublicInstanceField is:
Instance Public
Field MyPrivateConstField is:
Static Not-Public Literal
Namespace: System.Reflection
Assembly: mscorlib (in mscorlib.dll)
Assembly Versions: 1.0.5000.0, 2.0.0.0