Skip to content

Trouble declaring the variables...very confused....

Sayed Faiz

Asked Mar 28, 2009, 6:32 PM EDT1 answer
Share
LinkedInX
for some strange reason I am not able to do very simple stuffs, like declaring a variable...for example when I write 'private bool result' it shows red error lines under both private and bool in visual studio stating that " ; expected " for bool and "Invalid expression term 'private' "
here is a sample code below:

using System;
using System.Collections.Generic;
using System.Text;
using System.Data.OleDb;
using System.Data;

namespace DataAccessLayer
{
    public abstract class BaseDAL
    {
        public DataTable getMultipleData(string query)
          {
               private bool result;
           }

     }
}

where am i going wrong here?!?!?! very confused...im using .NET 2.0 and Visual Studio 2005

1 Answer

Know the answer? Post it. Somebody with the same question will find it here.

  • 0
    You cant declare member access operators on variables in a local (function) scope, they will always be private to the function. If you want to use a member access modifier (private, protected, protected internal, internal, public) you should declare the variable in the scope of the class.

    public class MyClass
    {
       private bool myBoolOne; // works fine
       bool myBoolTwo; // will work as well, will default to "private" member access

       public void MyFunction()
       {
          private bool myBoolThree; // will not work, cannot declare member access operator in local scope
          bool myBoolFour; // works fine, is declare in scope of function
       }
    }
    0