T
titan nyquist
Can you make volatile structures in C#?
I have a static class, to have "global" variables. This allows the
whole program to see them. I make them "volatile" to avoid multi-
threading accessing issues.
That works.
THE PROBLEM: In that static class, I want to combine some variables
inside a structure, and then make a variable of that structure type,
and make it volatile.
But it doesn't work:
------------------------------------------------------
using System;
using System.Collections.Generic;
using System.Text;
namespace VolatileStructuresTest
{
class Program
{
static void Main(string[] args)
{
TestClass.a = 1;
Console.WriteLine("a = " + TestClass.a);
TestClass.testStruct.b = 2;
Console.WriteLine("b = " + TestClass.testStruct.b);
}
}
}
static class TestClass
{
static volatile public int a;
public struct TestStruct
{
public int b;
};
static /*volatile*/ public TestStruct testStruct = new TestStruct();
}
------------------------------------------------------
Uncomment out /*volatile*/, in the last line of code, to get this
error:
'TestClass.testStruct': a volatile field cannot be of the type
'TestClass.TestStruct'
Why is this?
Titan
I have a static class, to have "global" variables. This allows the
whole program to see them. I make them "volatile" to avoid multi-
threading accessing issues.
That works.
THE PROBLEM: In that static class, I want to combine some variables
inside a structure, and then make a variable of that structure type,
and make it volatile.
But it doesn't work:
------------------------------------------------------
using System;
using System.Collections.Generic;
using System.Text;
namespace VolatileStructuresTest
{
class Program
{
static void Main(string[] args)
{
TestClass.a = 1;
Console.WriteLine("a = " + TestClass.a);
TestClass.testStruct.b = 2;
Console.WriteLine("b = " + TestClass.testStruct.b);
}
}
}
static class TestClass
{
static volatile public int a;
public struct TestStruct
{
public int b;
};
static /*volatile*/ public TestStruct testStruct = new TestStruct();
}
------------------------------------------------------
Uncomment out /*volatile*/, in the last line of code, to get this
error:
'TestClass.testStruct': a volatile field cannot be of the type
'TestClass.TestStruct'
Why is this?
Titan