Solved

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

Posted on 2011-09-25
4
153 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
ID: 36596511
Your error is elsewhere.  Check the integrity of your class (esp. mismatched braces, missing semicolon, etc.)
0
 
LVL 14

Expert Comment

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

Expert Comment

by:rajapandian_81
ID: 36597195
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
ID: 36597427
Note: you can assign values at class level, but only in the initializer, such as:

string new_time_sent_range = "l";

0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

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…
Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

947 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

22 Experts available now in Live!

Get 1:1 Help Now