Suppose I have a file ABC.CS
in that file I have a class ABC
as below and method Test()
:
public class ABC
{
public
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.