Gets the attributes of the field reflected by
the current instance.
[Edit]
Value
A System.Reflection.FieldAttributes value that indicates the attributes of
the field reflected by the current instance.
[Edit]
Remarks
Example
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
Requirements
Namespace: System.Reflection
Assembly: mscorlib (in mscorlib.dll)
Assembly Versions: 1.0.5000.0, 2.0.0.0