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 AhmedPosted May 18, 2014, 7:37 AM
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());
}
VulpesPosted May 18, 2014, 12:08 PM
private void button1_Click(object sender, EventArgs e)
Posted May 18, 2014, 7:31 AM
Did You test it?
it doesnt work.
Khan Abrar AhmedPosted May 18, 2014, 7:28 AM
{
int value = (int)paramet[0];
value = value + 2;
paramet[0] =value;
}
Posted May 18, 2014, 7:27 AM
I need it to do without return type of int.
In Your method its not void but int.
Khan Abrar AhmedPosted May 18, 2014, 7:21 AM
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;
}