Access variable from another method in another class

前端 未结 7 1369
闹比i
闹比i 2020-12-12 06:27

Suppose I have a file ABC.CS in that file I have a class ABC as below and method Test():

public class ABC
{
   public          


        
相关标签:
7条回答
  • 2020-12-12 07:06

    Theoretically you cannot do so, but if you change the method a little bit you may get what you want.

    Declare a list of objects publicly and access it from the other class.

    public  List<object> differentVarColl = new List<object>();
    
        void MethodA()
        {
    
            int a = 0;
            int b = 10;
            double c = -90;
    
            DataTable dtData = new DataTable();
    
            //Do rest of things
    
    
            differentVarColl.Add(a);
            differentVarColl.Add(b);
            differentVarColl.Add(c);
            differentVarColl.Add(dtData);
    
        }
    

    From other method, iterate the list and store them in new some variables depending on their type.

    I hope this helps.

    0 讨论(0)
提交回复
热议问题