2

I have a problem with error CS0236.

public class Converter
{
    public string Celsiusz { get; set; }
    public string Fahrenheit { get; set; }
    public string Kelvin{ get; set; }
    public string Rankinen { get; set; }
    public string Reaumur { get; set; }
    public string Romer { get; set; }
    public string Delisle { get; set; }
    public string Newton { get; set; }


    double CelsiuszDouble;

    bool bupa = double.TryParse(Newton, out CelsiuszDouble); 
 }

Are coming two errors:

First:

error CS0236: A field initializer cannot reference the non-static field, method, or property Converter.Newton

Second:

error CS0236: A field initializer cannot reference the non-static field, method, or property Converter.CelsiuszDouble

3
  • In the error Converter.Nevton isn't that a spelling mistake in your code in that case? Commented Oct 27, 2016 at 13:13
  • 3
    That last line of code doesn't make sense in the class definition. I suspect it should be in a method somewhere. (Both of the last lines of code, actually.) Commented Oct 27, 2016 at 13:15
  • sorry the errors was written in may language and I translated to english with mistake. I fixed already Commented Oct 27, 2016 at 13:20

2 Answers 2

3

I agree with @David You cant write such a code in class definition . You must write that part bool=.... inside either Constructor or a Method.

Sign up to request clarification or add additional context in comments.

Comments

1

This code is trying to access the public property of a non-static class, therefore you have no instance of it to access.

 bool bupa = double.TryParse(Newton, out CelsiuszDouble); 

If you change the property to have a private backing field, you could use that in your code.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.