473,831 Members | 2,311 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

C# / ASP.NET Question: how to use a class variable without initiate



how to use a class variable without initiate

for example:

ClassA { int var1; }

ClassB{

ClassA aa = new ClassA(); // omit this

aa.var1 = 1; // call this variable directly

}

I am thinking I may try something like this:

ClassA::var1 = 1;

hope you can make me clear.

thanks

larry
Nov 16 '05 #1
2 1414
On Tue, 25 Jan 2005 19:37:03 GMT, Larry wrote:
how to use a class variable without initiate

for example:

ClassA { int var1; }

ClassB{

ClassA aa = new ClassA(); // omit this

aa.var1 = 1; // call this variable directly

}

I am thinking I may try something like this:

ClassA::var1 = 1;

hope you can make me clear.

thanks

larry


Make var1 static and you can access as you have described. Ex:

class ClassA
{
public static int var1;
}

class ClassB
{
public void DoSomethingWith ClassA()
{
ClassA.var1 = 1;
}
}

Read up on the static keyword to understand the implications of this.
--
Tom Porterfield
Nov 16 '05 #2
thanks a lot for all of you.

"Tom Porterfield" <tp******@mvps. org> wrote in message
news:1o******** *******@tpporte rmvps.org...
On Tue, 25 Jan 2005 19:37:03 GMT, Larry wrote:
how to use a class variable without initiate

for example:

ClassA { int var1; }

ClassB{

ClassA aa = new ClassA(); // omit this

aa.var1 = 1; // call this variable directly

}

I am thinking I may try something like this:

ClassA::var1 = 1;

hope you can make me clear.

thanks

larry


Make var1 static and you can access as you have described. Ex:

class ClassA
{
public static int var1;
}

class ClassB
{
public void DoSomethingWith ClassA()
{
ClassA.var1 = 1;
}
}

Read up on the static keyword to understand the implications of this.
--
Tom Porterfield

Nov 16 '05 #3

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

Similar topics

11
2106
by: Joseph Turian | last post by:
Fellow hackers, I have a class BuildNode that inherits from class Node. Similarly, I have a class BuildTree that inherits from class Tree. Tree includes a member variable: vector<Node> nodes; // For clarity, let this be "orig_nodes" BuildTree includes a member variable:
4
2960
by: Daniel | last post by:
I need to build the maze board(like 2d array) using a tree. But I find that my buildTree function doesn't work. Could anyone give me some hints on debugging it? Thanks bool BuildTree(TreeNodePtr *T, int x, int y) { if (boardSize == 0) //boardSize is a global variable { return TRUE; } else {
7
1359
by: Bob Morvay | last post by:
I am trying to determine how far I should go in encapsulating data. As I understand it, OO practices state to create private member variables and use these variables in your publicly accessible functions. This requires the programmer to set the variables using the setters of the class before calling the function. The problem that I see is that the coder doesn't know the private variables needed by the public function without viewing the...
6
1680
by: tshad | last post by:
I am playing with Inheritance and want to make sure I understand it. I have the following Classes: ******************************************* Public Class AuthHeader:Inherits SoapHeader Public AuthHeaderName As String Public SessionKey As String = "Default" End Class Public Class ServiceTicket:Inherits AuthHeader
5
1714
by: Bryan | last post by:
I have a class 'TagType' with an ilist member 'Props' that holds a collection of another class called 'Prop'. I let the user create TagTypes and save multiple properties (Props) in them. I am having a problem storing a Prop object in a TagType object. The code below is giving me a "Object reference not set to an instance of an object." error. I don't understand why Dim t As TagType = Me.lstTagTypes.SelectedItem 'user selects TagType...
25
1507
by: Brian | last post by:
Can some one please tell me what I'm doing wrong. I'm trying to create a class called Dog, but Visual Basic tells me that I can't enter Wolf.age....why is this? Public Class Form1 Public Class DOG Dim COLOUR As String Dim AGE As Integer Dim NAME As String
6
3380
by: Stephen Torri | last post by:
I am trying to produce a singleton class that I can use throughout my library to write tracing information to a file. My intent was to design such that someone using the library in its debug mode would be able to see what was happening without having to use a debugger to step through each instruction. What they would do is run their program and view the tracing file output. If there was something wrong then they would use the debugger of...
20
4052
by: tshad | last post by:
Using VS 2003, I am trying to take a class that I created to create new variable types to handle nulls and track changes to standard variable types. This is for use with database variables. This tells me if a variable has changed, give me the original and current value, and whether the current value and original value is/was null or not. This one works fine but is recreating the same methods over and over for each variable type. ...
8
1674
by: fabian.lim | last post by:
Hi, I have a question on constant variables. In the following code snippet, I have a function assign() that takes in an iterator to the private variable v, the number of stuff to assign (int n), and the information to assign (a const pointer to a class object Vector<TYPE>. According to the arrow below, I put a const keyword in the function. To my knowledge, this means that all private variables in this object
0
9793
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9642
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10777
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10494
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10534
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9317
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5620
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4417
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
3076
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.