c#.net - setting a value to a variable---does a missing bracket cause this error?

I get this error, maybe the braces are not matched up:

    string new_time_sent_range = null;

    new_time_sent_range = "l";

invalid token '=' in class, struct, or interface declaration
LVL 10
GlobaLevelProgrammerAsked:
Who is Participating?

Improve company productivity with a Business Account.Sign Up

x
 
Bill NolanConnect With a Mentor Owner, Lead Technology ProgrammerCommented:
Your error is elsewhere.  Check the integrity of your class (esp. mismatched braces, missing semicolon, etc.)
0
 
binaryevoCommented:
I concur with Slimfinger.  The code you provided looks fine...
0
 
rajapandian_81Commented:
Hi,

You can not assign values to variable in class level. You can do only declaration. Modify the code like below:
    public partial class Form1 : Form
    {
        string new_time_sent_range = null;        

        public Form1()
        {
            InitializeComponent();
            new_time_sent_range = "l";

Open in new window

0
 
Bill NolanOwner, Lead Technology ProgrammerCommented:
Note: you can assign values at class level, but only in the initializer, such as:

string new_time_sent_range = "l";

0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.