473,387 Members | 1,606 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Global Variable

I know in vb.net you can declare a global variable, but how do you declare one in c#. I want to make a connection class with the path and have it accessed by anther class or method.
Thank you
Nov 16 '05 #1
3 2265
Hi freddy,

Declare that variable as a static member of a class. This way you can access
it from anyware.

--
HTH
Stoitcho Goutsev (100) [C# MVP]
"freddy" <fr****@discussions.microsoft.com> wrote in message
news:00**********************************@microsof t.com...
I know in vb.net you can declare a global variable, but how do you declare one in c#. I want to make a connection class with the path and have it
accessed by anther class or method.

Thank you

Nov 16 '05 #2
You have to declare public variable inside the class like

public string myVariable = "Test";

You have to store MyOtherClass as member in the class where you want to
access to like

public MyOtherClass mOtherClass;

To access the public variable in of MyOtherClass you can say

mOtherClass.MyVariable

Other way is to declare variable as static member. VB approach wont be
applicable in c# in this case.

--
Shak
(Houston)
"freddy" <fr****@discussions.microsoft.com> wrote in message
news:00**********************************@microsof t.com...
I know in vb.net you can declare a global variable, but how do you declare one in c#. I want to make a connection class with the path and have it
accessed by anther class or method.

Thank you

Nov 16 '05 #3
Hi feddy,

Static field is the way to go :)
--
Regards,
Chua Wen Ching :)
"Shakir Hussain" wrote:
You have to declare public variable inside the class like

public string myVariable = "Test";

You have to store MyOtherClass as member in the class where you want to
access to like

public MyOtherClass mOtherClass;

To access the public variable in of MyOtherClass you can say

mOtherClass.MyVariable

Other way is to declare variable as static member. VB approach wont be
applicable in c# in this case.

--
Shak
(Houston)
"freddy" <fr****@discussions.microsoft.com> wrote in message
news:00**********************************@microsof t.com...
I know in vb.net you can declare a global variable, but how do you declare

one in c#. I want to make a connection class with the path and have it
accessed by anther class or method.


Thank you


Nov 16 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
by: David Hitillambeau | last post by:
Hi guys, As I am new to Python, i was wondering how to declare and use global variables. Suppose i have the following structure in the same module (same file): def foo: <instructions>...
4
by: Andrew V. Romero | last post by:
I have been working on a function which makes it easier for me to pull variables from the URL. So far I have: <script language="JavaScript"> var variablesInUrl; var vArray = new Array(); ...
4
by: Dan Elliott | last post by:
Hello, Converting from a working C program to C++, I run into the following error: I have a header: (header.h) namespace shared{ ... struct X{ ...
2
by: Thomas Matthews | last post by:
Hi, I'm getting linking errors when I declare a variable in the global scope, but not inside a function. The declarations are the same (only the names have been changed...). class Book {...
8
by: lawrence | last post by:
I'm learning Javascript. I downloaded a script for study. Please tell me how the variable "loop" can have scope in the first function when it is altered in the second function? It is not defined...
17
by: MLH | last post by:
A97 Topic: If there is a way to preserve the values assigned to global variables when an untrapped runtime error occurs? I don't think there is, but I thought I'd ask. During development, I'm...
10
by: Charles O'Flynn | last post by:
As a complete newcomer (2-3 days) to PHP, although not to programming in general, I have 'dived in' to start a small project to read and parse an XML data stream. I have already worked out most of...
9
by: Ed Jensen | last post by:
I'm having a vexing problem with global variables in Python. Please consider the following Python code: #! /usr/bin/env python def tiny(): bar = for tmp in foo: bar.append(tmp) foo = bar
1
weaknessforcats
by: weaknessforcats | last post by:
C++: The Case Against Global Variables Summary This article explores the negative ramifications of using global variables. The use of global variables is such a problem that C++ architects have...
112
by: istillshine | last post by:
When I control if I print messages, I usually use a global variable "int silent". When I set "-silent" flag in my command line parameters, I set silent = 1 in my main.c. I have many functions...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.