Im using windows form applicaton
and try using a method that returns a value and have a parmeterlist input.

I try to creat a program that converts a number of kilobytes (KB) to byte. The program's user to specify the number of KiB and the program will print the same number of bytes.
For conversion of KB to change the program should call a separate method that you have defined. The method is via its parameter list to load KiB number, convert the number of KB to the corresponding value in bytes and return that value.

Any idea

5 Years
Discussion Span
Last Post by tony75

Thanks Sir
Her is my solution but I got error,I hope you can help me.

public partial class Form1 : Form
        public Form1()

        private void btnconverter_Click(object sender, EventArgs e)
            int kib = 0 ;
             kib = Convert.ToInt32(txtKib.Text);
             txtResult.Text = Convert.ToString(calc(kib));

        private int calc(int numberOfKib);
            return  numberOfKib/1024

Edited by tony75


As I understand you well, the user inputs in a textbox a number of KB after clicking a button the program calculates the number of bytes and puts the result in another textbox. Correct?
If answer is yes, then in your calc method, you should multiply by 1024, instead of dividing.


Yes you understan me very well
But I got those error?

Error 1 Invalid token '{' in class, struct, or interface member declaration

Error 2 Invalid token '1024' in class, struct, or interface member declaration

Edited by diafol: fixed formatting

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.