简体   繁体   中英

The best overloaded Method has some invalid arguments and Cannot convert type

Banking object1 = new Banking(t1.Text);
MessageBox.Show(object1.transact(t2.Text));

It's giving an error of invalid arguments in the method and also that it cant convert from String to float. Banking is the class and object1 is an object, transact is a method. As long as I believe there is no error in the method still below I'm pasting my class and method code:

class Banking
    {   string bankName;
        float amount;

        public Banking(string name)
        {
            bankName = name;
        }
        public string transact(float a)
        {
            amount = a * 7 / 100;
            float total =Convert.ToSingle(amount + a);
            return "Your amount of Rupees : " + total + "has been deposited in " + bankName;
        }
    }

Here is the error list:

Error 1 The best overloaded method match for 'WindowsFormsApplication1.Banking.transact(float)' has some invalid arguments.


Error 2 Argument '1': cannot convert from 'string' to 'float'

值从字符串解析为浮点数。

MessageBox.Show(object1.transact(Single.Parse(t2.Text)));

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM