Reputation: 45
I'm working with a thermal camera and the provided SDK. But the problem is that I'm real beginner in .NET because normally I develop in PHP.
So what I'm trying to do is passing variables from a private void to another private void. For example, I'm trying to pass the variable ToPass from the void "OnDetect" to the void OnReferenceRegion.
private void OnDetect(CallbackEventArgument callbackArgument)
{
string ToPass = "This string needs to be passed";
}
Here is the OnReferenceRegion void
private void OnReferenceRegion(object sender, System.Windows.Input.MouseButtonEventArgs e)
{
String completeString = "";
completeString = ToPass;
}
Upvotes: 1
Views: 2204
Reputation: 331
There are 4 ways to "pass variables" between void-functions:
In your case you probably want the first one, i.e. declaring a field/property in the containing class or any other scope those two functions have access to.
Upvotes: 3
Reputation: 20373
You can add a private field, which has class-wide scope and thus can be accessed by both methods:
class YourClass
{
private string toPass; // Has class-wide scope
private void OnDetect(CallbackEventArgument callbackArgument)
{
toPass = "This string needs to be passed";
}
private void OnReferenceRegion(object sender, System.Windows.Input.MouseButtonEventArgs e)
{
string completeString = "";
completeString = toPass;
}
}
Upvotes: 3