Thank you for the excellent input.
I am able to read a key and select a function from the key.
c# Xamarin.Android mobile how do you pass a char variable from MainActivity to another class
Developer technologies | .NET | Xamarin
-
joe puhich 101 Reputation points
2021-01-09T02:18:22.8+00:00
1 additional answer
Sort by: Most helpful
-
JessieZhang-MSFT 7,716 Reputation points Microsoft External Staff
2021-01-04T10:18:32.637+00:00 Hello,
Welcome to our Microsoft Q&A platform!
You can pass the string as a parameter to another class.
You can refer to the following code:
public class TestClass
{string mStr; public TestClass(string str) { this.mStr = str; }
}
usage :
string scankeyinput = "test string"; TestClass model = new TestClass(scankeyinput);
Update
From the way you accessed string
mStr
, you should use thestatic
modifier to declare this static member:public class TestClass { public static string MyStr ="default string"; }
And use like this:
string scankeyinput = "test string"; // TestClass model = new TestClass(scankeyinput); TestClass.MyStr = scankeyinput; // assign string `scankeyinput ` to field `MyStr ` in class `TestClass`. // you can access MyStr like this System.Diagnostics.Debug.WriteLine(" TestClass.MyStr = " + TestClass.MyStr);
For more details, you can check: https://learn.microsoft.com/en-us/dotnet/csharp/language-reference/keywords/static
Best Regards,
Jessie Zhang
---
If the response is helpful, please click "Accept Answer" and upvote it.Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.