Hello ,
in below method - How to return value with params keyword.It is possible if change Do method return type to int.But I need to do it with void and params keyword.
Thanks in advance.
private void button1_Click(object sender, EventArgs e)
{
int x = 1;
Do(x);
MessageBox.Show(x.ToString());
}
public void Do(params object [] paramet )
{
int value = (int)paramet[0];
value = value + 2;
}
Loading

Khan Abrar AhmedRank #778 · 3K reputationPosted May 18, 2014, 3:37 AM EDT
like
public void Do(params object [] paramet, out int value )
{
value = (int)paramet[0];
value = value + 2;
}
private void button1_Click(object sender, EventArgs e)
{
int x = 1;
Do(x,value out);
MessageBox.Show(value.ToString());
}
Khan Abrar AhmedRank #778 · 3K reputationPosted May 18, 2014, 3:21 AM EDT
private void button1_Click(object sender, EventArgs e)
{
int x = 1;
x= Do(x); or
Do(x);
MessageBox.Show(x.ToString());
}
public int Do(params object [] paramet )
{
int value = (int)paramet[0];
value = value + 2;
return
value ;
}
public int Do(params object [] paramet )
{
int value = (int)paramet[0];
value = value + 2;
paramet[0] =value;
}
Posted May 18, 2014, 3:27 AM EDT
I need it to do without return type of int.
In Your method its not void but int.
Khan Abrar AhmedRank #778 · 3K reputationPosted May 18, 2014, 3:28 AM EDT
{
int value = (int)paramet[0];
value = value + 2;
paramet[0] =value;
}
Posted May 18, 2014, 3:31 AM EDT
Did You test it?
it doesnt work.
VulpesRank #55 · 29.2K reputationPosted May 18, 2014, 8:08 AM EDT
private void button1_Click(object sender, EventArgs e)