TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Esteban Francisco
NA
3
3.5k
Passing a static var by reference
Jun 4 2011 12:13 AM
I am having trouble updating a static variable by reference. I have a parent class passing a static variable into new class constructor by reference. The parent class is the primary executable. The new class is in a separate DLL. I can easily change the value of the static variable in the new class's constructor and it's reflected in the parent. Unfortunately, I cannot update this static variable from another method in the new class.
The flow of my program is something like the following:
[code]
namespace Somewhere
{
public partial class TestReporter : Form
{
private TestForm tForm;
public static bool TestInProgress = false;
void someMethod()
{
tForm = new TestForm(ref TestInProgress);
}
}
}
[/code]
[code]
namespace OverTheRainbow
{
public class Test
{
public bool RainbowProgress = false;
public Test(ref bool prog)
{
RainbowProgress = prog;
}
void someOtherMethod()
{
RainbowProgress = true;
}
}
}
[/code]
So you see, I was hoping that calling someOtherMethod() in the TestForm class would update the parent's TestInProgress value. Unfortunately, I was wrong. Now, I am a C/C++ guy and my first though to solve this is pointers. I even tried to use pointers with C#, but with all the unsafe keywords and having to tell the compiler to use unsafe code, it just seemed way inappropriate. There has to be a way to update that boolean value in the parent class using something more
natural
to C#.
Can anyone help with this? Thank you so much!
Reply
Answers (
3
)
Label - text alignment
C# Coder Wanted for Server Software