Solved

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

Posted on 2011-09-25
4
152 Views
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
0
Comment
Question by:GlobaLevel
  • 2
4 Comments
 
LVL 7

Accepted Solution

by:
Slimfinger earned 500 total points
Comment Utility
Your error is elsewhere.  Check the integrity of your class (esp. mismatched braces, missing semicolon, etc.)
0
 
LVL 14

Expert Comment

by:binaryevo
Comment Utility
I concur with Slimfinger.  The code you provided looks fine...
0
 
LVL 12

Expert Comment

by:rajapandian_81
Comment Utility
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
 
LVL 7

Expert Comment

by:Slimfinger
Comment Utility
Note: you can assign values at class level, but only in the initializer, such as:

string new_time_sent_range = "l";

0

Featured Post

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

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…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…

743 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now