Created
February 20, 2013 01:41
-
-
Save robertlj/4991982 to your computer and use it in GitHub Desktop.
Volatile Field Look up Example
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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