0

I'm new to Programming and trying to do an first Program.

I want to use a Method for the User input to change Variables from the Main function. But i get the Error: "Member 'float.Parse(string)' cannot be accessed with an instance reference"

Here's my Code

                    
public class Program
{
    public static void Main()
    {   float salary = 0;
        float rentalFee;
        float powerCosts;
        float gez;
        bool gezMonth;
        float insurence;
        bool insurenceMonth;
        userOutput("Geben sie einen Wert für ihr Gehalt ein");
        salary = UserInput(Console.ReadLine());
        Console.WriteLine(salary);
        
    }
    private static float UserInput(string usrInput)
    {   
        float input= 0;
        input.Parse(usrInput);
        return input;
    }

i googled the error but i don't really understand the answers :D is this cause its public ? Should i do the UserInputs in the Main function directly ?

Paddy
  • 31
  • 4
  • 4
    Try `float input = float.Parse(usrInput);`. `Parse` is a static method and can only be statically invoked from the type not from an instance. – phuzi Jul 08 '21 at 11:11

1 Answers1

-1

Use

input = float.Parse(usrInput);

instead of

input.Parse(usrInput);

Refer to How to convert a string to a number (C# Programming Guide).

Wai Ha Lee
  • 8,598
  • 83
  • 57
  • 92