Solved - setting a value to a variable---does a missing bracket cause this error?

Posted on 2011-09-25
Last Modified: 2013-12-17
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
Question by:GlobaLevel
  • 2

Accepted Solution

Bill Nolan earned 500 total points
ID: 36596511
Your error is elsewhere.  Check the integrity of your class (esp. mismatched braces, missing semicolon, etc.)
LVL 14

Expert Comment

ID: 36596527
I concur with Slimfinger.  The code you provided looks fine...
LVL 12

Expert Comment

ID: 36597195

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()
            new_time_sent_range = "l";

Open in new window


Expert Comment

by:Bill Nolan
ID: 36597427
Note: you can assign values at class level, but only in the initializer, such as:

string new_time_sent_range = "l";


Featured Post

Guide to Performance: Optimization & Monitoring

Nowadays, monitoring is a mixture of tools, systems, and codes—making it a very complex process. And with this complexity, comes variables for failure. Get DZone’s new Guide to Performance to learn how to proactively find these variables and solve them before a disruption occurs.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

679 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question