Hi everyone...just going from console apps to windows forms apps....This is extremely basic and is annoying me now...

public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            MessageBox.Show("{0}",hello2(2));
        }

        public int hello2(int hello)
        {
            hello = 10 / 5;
            hello = Convert.ToInt32(hello);
                
            return hello;
        }

    }
}

I am trying to get the hello2 method to return the sum 10 / 5 and return 2...

works fine when I do it as a console app...

could anyone please give me a fix to this and tell me how they "transitioned" from console apps to windows forms...


thanks

Your call to Message.Show is wrong, you need to add String.Format like so:

MessageBox.Show(String.Format("{0}",hello2(2)));

Also, it doesn't matter what number gets passed as the parameter to your hello2 function, it will always show 10 / 5. A better implementation would be:

private void button1_Click(object sender, EventArgs e)
{
  MessageBox.Show(String.Format("{0}",hello2(10, 5)));
}

public int hello2(int numerator, int denominator)
{
  int hello = numerator / denominator;
  return hello;
}

thanks my friend, nice simple way of explaining...thanks for your help..another quick question...any recommended books on moving forward to windows forms?

Thanks!

u can also do instead

MessageBox.Show(String.Format("{0}",hello2(10, 5)));

MessageBox.Show(Convert.ToString(hello2(15,3)));
both sentex will perform same..

Regards...
Farhad

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.