Хранить данные в оперативной памяти - C#
Формулировка задачи:
есть два класса , нужно хранить общие данные, при чём хранить и изменять быстро, пробывал делать глобальные переменные, почему то не хочет работать
вот класс где объявляю глобальные переменные
public class PhotonServer : ApplicationBase
{
protected override PeerBase CreatePeer(InitRequest initRequest)
{
return new UnityClient(initRequest.Protocol, initRequest.PhotonPeer);
}
protected override void Setup()
{
var file = new FileInfo(Path.Combine(BinaryPath, "log4net.config"));
if (file.Exists)
{
LogManager.SetLoggerFactory(Log4NetLoggerFactory.Instance);
XmlConfigurator.ConfigureAndWatch(file);
}
}
protected override void TearDown()
{
}
} public class UnityClient:PeerBase
{
public Options _ph;
private readonly ILogger Log = LogManager.GetCurrentClassLogger();
public UnityClient(IRpcProtocol protocol, IPhotonPeer peer)
: base(protocol, peer)
{
Log.Debug("Connection:" + peer.GetRemoteIP());
}
protected override void OnDisconnect(DisconnectReason reasonCode, string reasonDetail)
{
Log.Debug("Disconnected");
}
protected override void OnOperationRequest(OperationRequest operationRequest, SendParameters sendParameters)
{
MySqlCommand command = new MySqlCommand();
string connectionString, commandString;
connectionString = "Data source=localhost;UserId=root;Password=6672019;database=game;";
MySqlConnection connection = new MySqlConnection(connectionString);
MySqlDataReader reader;
command.Connection = connection;
try
{
switch (operationRequest.OperationCode)
{
case 4:
if (operationRequest.Parameters.ContainsKey(1) && (operationRequest.Parameters[1].ToString() == "listbitv"))
{
string
avtor1= "";
_ph.gavtor = _ph.gavtor + "j";
avtor1 = _ph.gavtor.Count().ToString();
OperationResponse response = new OperationResponse(operationRequest.OperationCode);
response.Parameters = new Dictionary<byte, object> { { 10, avtor1 } };
SendOperationResponse(response, sendParameters);
}
break;
default:
Log.Debug("Unknown OperationRequest received!:" + operationRequest.OperationCode);
break;
}
}
catch (MySqlException ex)
{
Console.WriteLine("Error:\r\n{0}", ex.ToString());
}
finally
{
command.Connection.Close();
}
}
}public class Options
{
public string gavtor="1";
private Options() { }
}Решение задачи: «Хранить данные в оперативной памяти»
textual
Листинг программы
Test.Property = "34534"; Test.Property = "33333";