I am trying to assign a line of text as a string, so the string can be used in a message box, although the string fails to show up in the message box when the method is executed.
public string version { get; set; }
public void GetVersion()
{
var version = File.ReadAllText("version.txt");
}
private void SetBalloonTip()
{
notifyIcon1.Icon = SystemIcons.Exclamation;
notifyIcon1.BalloonTipTitle = "Test";
notifyIcon1.BalloonTipText = "This is version " + version;
notifyIcon1.BalloonTipIcon = ToolTipIcon.Error;
this.Click += new EventHandler(button1_Click);
}
Remove the
var:By adding the
var(or any variable type for that matter) you’re creating local variable, while you want to assign the class member.Happens to me too sometimes, and I see this as downside of
C#as I would expect at least a warning when compiling such a thing.