| | |
How to define global variable in C#
Please support our C# advertiser: Programming Forums - DaniWeb Sister Site
Thread Solved |
•
•
Join Date: Aug 2008
Posts: 83
Reputation:
Solved Threads: 18
efficacious,
You could just add a static List to a class. For example:
You could just add a static List to a class. For example:
C# Syntax (Toggle Plain Text)
public class Global { //instance variables static List<Global> CLASSES = new List<Global>(); public static Global this[int n] { get { return CLASSES[n]; } } public Global() { CLASSES.Add(this); } }
•
•
Join Date: Aug 2008
Posts: 83
Reputation:
Solved Threads: 18
•
•
•
•
i'm still kinda a noob at C# can u show how i can use that class to make new global variables..ty
C# Syntax (Toggle Plain Text)
using System; using System.Collections.Generic; public class Global { private static readonly List<Global> CLASSES = new List<Global>(); public static int Count { get { return CLASSES.Count; } } public static Global Get(int index) { return CLASSES[index]; } public int value; public Global() { CLASSES.Add(this); } } public static class Test { static void Main() { new Global(); Global.Get(0).value = 1; Console.WriteLine(Global.Get(0).value); Console.ReadKey(); } }
![]() |
Similar Threads
Other Threads in the C# Forum
- Previous Thread: report
- Next Thread: Uninstall C# application
Views: 93691 | Replies: 17
| Thread Tools | Search this Thread |
Tag cloud for C#
.net access algorithm array barchart bitmap box button buttons c# chat check checkbox class client code color combobox control conversion csharp custom database datagridview dataset datetime degrees draganddrop drawing encryption enum excel file files form format forms ftp function gcd gdi+ httpwebrequest image index input install java label list listbox listener login mandelbrot math mouseclick mysql networking object operator oracle path photoshop picturebox post prime programming radians regex remote remoting resource richtextbox save saving serialization server sleep socket sql statistics stream string table tcp text textbox thread time timer treeview update usercontrol validation view visualstudio webbrowser windows winforms wpf xml





