Check if a field is literal in CSharp

Description

The following code shows how to check if a field is literal.

Example


using System;//ww w .  j  a va2s  .  c o m
using System.Reflection;

public class Example
{
    public int f_public;
    internal int f_internal;
    protected int f_protected;
    protected internal int f_protected_public;

    public static void Main()
    {
        foreach (FieldInfo f in typeof(Example).GetFields(BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public))
        {
            Console.WriteLine(f.Name);
            Console.WriteLine(f.IsLiteral);
        }
    }
}

The code above generates the following result.





















Home »
  C# Tutorial »
    Reflection »




Array
Constructor
Event
Field
Interface
Method
Properties
Type