我有一个类似于此的单例类
public class Singleton
{
private static Singleton m_instance;
private Timer m_timer;
private static List<CustomObject> m_cacheObjects;
private Singleton()
{
m_cacheObjects = new List<CustomObject>();
m_timer= new Timer(MyTimerCallBack,
null,
TimeSpan.FromSeconds(60),
TimeSpan.FromSeconds(60));
}
public static Singleton Instance
{
get
{
if (m_instance == null)
{
m_instance = new Singleton();
}
return m_instance;
}
}
private void MyTimerCallBack(object state)
{
//******** Update the list by interval here ******************
m_cacheObjects = UpdateTheList();
}
public void CallMe()
{
foreach (CustomObject obj in m_cacheObjects)
{
// do …Run Code Online (Sandbox Code Playgroud) 我有一个if if语句,它永远不会返回True.怎么了?
我是php和regex的新手.
$String = '123456';
$Pattern = "/\d{2}$/";
//i intend to match '56', which is the last two digit of the string.
if(preg_match($Pattern $String ,$matches))
{
echo 'Matched';
}
Run Code Online (Sandbox Code Playgroud)
如果$Pattern是"/^\d{2}/",则返回true并匹配数字'12';
编辑:我的错误.上面的代码运行良好.在实际的代码中,$ String是从变量中分配的,而alwasys最终得到了一个我不知道的点.匹配上面最后两位数的要求仅用于问题解释.在实际代码中需要正则表达式.