Click here to Skip to main content
15,892,199 members
Home / Discussions / C#
   

C#

 
GeneralRe: help provider Pin
Heath Stewart19-May-04 9:45
protectorHeath Stewart19-May-04 9:45 
GeneralDataSet byte array storage Pin
Anfernius19-May-04 8:39
Anfernius19-May-04 8:39 
GeneralRe: DataSet byte array storage Pin
Dave Kreskowiak19-May-04 8:58
mveDave Kreskowiak19-May-04 8:58 
GeneralRe: DataSet byte array storage Pin
Heath Stewart19-May-04 9:04
protectorHeath Stewart19-May-04 9:04 
GeneralRe: DataSet byte array storage Pin
Dave Kreskowiak19-May-04 9:33
mveDave Kreskowiak19-May-04 9:33 
GeneralRe: DataSet byte array storage Pin
Heath Stewart19-May-04 9:36
protectorHeath Stewart19-May-04 9:36 
GeneralGlobal Variables in Visual C# Pin
Anonymous19-May-04 8:32
Anonymous19-May-04 8:32 
GeneralRe: Global Variables in Visual C# Pin
Heath Stewart19-May-04 8:55
protectorHeath Stewart19-May-04 8:55 
There is no such thing as "global variables" using C# and, IIRC, isn't allowed by the CLI (though you can define global functions, i.e. methods not defined by a class).

Instead, you can use static fields or properties (properties are recommended for added safety since you can check the value being assigned before setting it):
public sealed class Options
{
  private Options() {} // Prevent instantiation
  private static int option1;
  private static string option2;
  public static int Option1
  {
    get { return option1; }
    set
    {
      if (value < 0) throw new ArgumentException();
      option1 = value;
    }
  }
  public static string Option2
  {
    get { return option2; }
    set
    {
      if (value == null) throw new ArgumentNullException();
      option2 = value;
    }
  }
}
To set and get these, you simply refer to the static member:
string option1 = Options.Option2;
Options.Option1 = 10;
If you're new to C#, you should also read the Visual C# Language[^] documentation in the Visual Studio .NET product documentation.

 

Microsoft MVP, Visual C#
My Articles
GeneralRe: Global Variables in Visual C# Pin
sreejith ss nair19-May-04 20:40
sreejith ss nair19-May-04 20:40 
GeneralHelp reqd to Show Help .... Pin
fayazhsn19-May-04 8:25
fayazhsn19-May-04 8:25 
GeneralRe: Help reqd to Show Help .... Pin
Heath Stewart19-May-04 8:52
protectorHeath Stewart19-May-04 8:52 
GeneralRe: Help reqd to Show Help .... Pin
fayazhsn19-May-04 9:05
fayazhsn19-May-04 9:05 
GeneralRe: Help reqd to Show Help .... Pin
Heath Stewart19-May-04 9:43
protectorHeath Stewart19-May-04 9:43 
GeneralVS.NET Enterprise Architect vs. Professional Pin
Anonymous19-May-04 8:10
Anonymous19-May-04 8:10 
GeneralRe: VS.NET Enterprise Architect vs. Professional Pin
Grimolfr19-May-04 8:18
Grimolfr19-May-04 8:18 
GeneralRe: VS.NET Enterprise Architect vs. Professional Pin
Anonymous20-May-04 2:27
Anonymous20-May-04 2:27 
GeneralRe: VS.NET Enterprise Architect vs. Professional Pin
Dave Kreskowiak20-May-04 3:13
mveDave Kreskowiak20-May-04 3:13 
GeneralRe: VS.NET Enterprise Architect vs. Professional Pin
Anonymous20-May-04 7:37
Anonymous20-May-04 7:37 
GeneralRe: VS.NET Enterprise Architect vs. Professional Pin
Dave Kreskowiak20-May-04 11:52
mveDave Kreskowiak20-May-04 11:52 
GeneralRe: VS.NET Enterprise Architect vs. Professional Pin
Anonymous21-May-04 2:12
Anonymous21-May-04 2:12 
GeneralRe: VS.NET Enterprise Architect vs. Professional Pin
Anonymous25-May-04 19:26
Anonymous25-May-04 19:26 
Generalregd treeView control Pin
karteek19-May-04 8:06
karteek19-May-04 8:06 
GeneralRe: regd treeView control Pin
Dave Kreskowiak19-May-04 8:31
mveDave Kreskowiak19-May-04 8:31 
GeneralRe: regd treeView control Pin
Heath Stewart19-May-04 8:49
protectorHeath Stewart19-May-04 8:49 
GeneralRe: regd treeView control Pin
karteek19-May-04 9:04
karteek19-May-04 9:04 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.