Skip to content

Instantly share code, notes, and snippets.

@NNNIC
Created January 1, 2018 21:04
Show Gist options
  • Save NNNIC/393d1c68fbafced8dfe942c6e19c99ba to your computer and use it in GitHub Desktop.
Save NNNIC/393d1c68fbafced8dfe942c6e19c99ba to your computer and use it in GitHub Desktop.
Read Once Value
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
public class ReadOnceValue<T>
{
T m_resetVal;
T m_val;
public ReadOnceValue(T resetVal)
{
m_resetVal = resetVal;
}
public ReadOnceValue()
{
m_resetVal = default(T);
}
public void Set(T val) { m_val = val; }
public T Get() {
var x = m_val;
m_val = m_resetVal;
return x;
}
public T Peek()
{
return m_val;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment