Skip to content

Instantly share code, notes, and snippets.

@robertlj
Created February 20, 2013 01:41
Show Gist options
  • Save robertlj/4991982 to your computer and use it in GitHub Desktop.
Save robertlj/4991982 to your computer and use it in GitHub Desktop.
Volatile Field Look up Example
using System;
using System.Linq;
namespace VolatileFieldExampleMono
{
public class Test
{
public volatile int Counter = 0;
public volatile int Counter2 = 2;
public int Counter3 = 3;
public int Conter4 = 4;
public string hi = "Whats up?";
public string bye = "C ya";
}
class MainClass
{
public static void Main (string[] args)
{
/*
var field = typeof(Test).GetField ("Counter");
bool isVolatile = field.GetRequiredCustomModifiers ().Any (x => x == typeof(System.Runtime.CompilerServices.IsVolatile));
Console.WriteLine ("Counter is a volitale field is: {0}", isVolatile.ToString ());
Console.ReadKey ();
*/
var fields = typeof(Test).GetFields ();
foreach (var FieldList in fields) {
if (FieldList.GetRequiredCustomModifiers().Any(x => x == typeof(System.Runtime.CompilerServices.IsVolatile))) {
Console.WriteLine("The volatile fields in the Test class are: {0}", FieldList.Name.ToString());
}
}
Console.ReadKey ();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment