是否可以将变量分配给另一个变量,当您更改第二个变量时,更改会向下变为第一个变量?
像这样.
int a = 0;
int b = a;
b = 1;
Run Code Online (Sandbox Code Playgroud)
现在b和a都= 1.
我问这个的原因是因为我有4个我正在跟踪的对象,并且我使用名为currentObject的第5个对象跟踪每个对象,该对象等于用户正在使用的4个对象中的任何一个.但是,我想对currentObject进行一些更改,然后让它成为它所来自的变量的瀑布.
谢谢
我试着搜索这个,但我甚至不确定如何用它来搜索.
我试图做的是有一个类,每次我访问它来改变它,我真的得到并设置会话的价值.
这是我正在尝试做的事情(到目前为止我所做的).
public class example
{
public int prop1 {get;set;}
public static example Instance
{
return (example)(HttpContext.Current.Session["exampleClass"] ?? new example());
}
}
public class main
{
protected void Page_Load(object sender, EventArgs e)
{
example.Instance.prop1 = "aaa"; //stores value into session
txtInput.Text = example.Instance.prop1; //retrieves value from session
}
}
Run Code Online (Sandbox Code Playgroud)
我希望这对我想要做的事情有意义.
任何帮助将不胜感激,谢谢.
我创建了一个新类,我得到一个空引用异常,我无法弄清楚为什么.
你调用的对象是空的.
namespace TIMBaseClasses.ReturnerTracking
{
[Serializable]
public class Returner
{
private Guid _returnerID;
private string _clientIP;
public Guid returnerID {get { return _returnerID; } set { _returnerID = value; }}
public string clientIP {get { return _clientIP; } set { _clientIP = value; }}
/// <summary>Constructor that sets the default values as needed</summary>
public Returner()
{
returnerID = Guid.Empty;
clientIP = string.Empty;
}
public static Returner Instance
{
get
{
var ret = (Returner)(HttpContext.Current.Session["Returner"] ?? new Returner());
HttpContext.Current.Session["Returner"] = ret; …Run Code Online (Sandbox Code Playgroud)