c# Xamarin.Android mobile how do you pass a char variable from MainActivity to another class

joe puhich 101 Reputation points
2021-01-03T20:16:23.31+00:00

52876-screenshot-721.png52981-screenshot-720.png

Developer technologies | .NET | Xamarin
0 comments No comments
{count} votes

Accepted answer
  1. joe puhich 101 Reputation points
    2021-01-09T02:18:22.8+00:00

    Thank you for the excellent input.
    I am able to read a key and select a function from the key.

    0 comments No comments

1 additional answer

Sort by: Most helpful
  1. 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 the static 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.


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.