How to call a method with parameters from another method?

Updated on May 18, 2018 in [A] C# .Net
Share on Facebook0Tweet about this on TwitterShare on Google+0Share on Reddit0
1 on May 18, 2018

Hi everyone, I’m new to learning C# programming and I’m interested to know is there any way that we can call a method like so?

Here is the declaration of how I want to call that particular method:

public void ABC(parameter A)
{
    ....//do something here
}
 
public void DEF(parameter B)
{
    var abc = def; //which is the input argument for method ABC
 
     //calling method ABC
     ABC(abc);
}
 
public void GHI(object sender, RoutedEventArgs e)
{
    //this is like a start button and I'd like to perform method ABC(abc) over here
    ABC(abc);
}
 

 

How can I do that? If you guys need more information of my code, I’m willing to show it here. Thank you!

  • Liked by
Reply
0 on May 18, 2018

I’m not quite sure what you’re asking for.

You can’t just “route” parameters from one method to another. What you would do is wither save the parameters to a variable in one method and use that variable instead of parameters in the other, or you call one method from within another, and just transfer the parameters like that.

 

var abc;
public void ABC(parameter A)
{
 ....//do something here
}
public void DEF(parameter B)
{
 var abc = B; //which is the input argument for method ABC
 ...//do something else
}
public void GHI(object sender, RoutedEventArgs e)
{
DEF(e);
ABC(abc);
}

 

  • Liked by
Reply
Cancel