Created
January 1, 2018 21:04
-
-
Save NNNIC/393d1c68fbafced8dfe942c6e19c99ba to your computer and use it in GitHub Desktop.
Read Once Value
This file contains 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.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