473,320 Members | 1,955 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,320 software developers and data experts.

PROBLEM in public class

Hi,

I have a problem with the public class. I am trying to save the last
identifier which I am getting correctrly but when I try to read I am
getting 0. The public class is like this:
public class global_var

{
private int record_id;

public int int_record_id

{
set {record_id = value;}
get {return record_id;}
}

}


and the code to read is:
global_var GlobalVariables = new global_var();

MessageBox.Show(GlobalVariables.int_record_id.AsSt ring());

to set the value I am using:

GlobalVariables.int_record_id = some_int_figure_here;


many Thanks,
Jassim Rahma

*** Sent via Developersdex http://www.developersdex.com ***
Nov 17 '05 #1
5 1464
"Jassim Rahma" <jr****@hotmail.com> a écrit dans le message de news:
#f**************@TK2MSFTNGP09.phx.gbl...
I have a problem with the public class. I am trying to save the last
identifier which I am getting correctrly but when I try to read I am
getting 0. The public class is like this:

public class global_var

{
private int record_id;

public int int_record_id

{
set {record_id = value;}
get {return record_id;}
}

}

and the code to read is:

global_var GlobalVariables = new global_var();

MessageBox.Show(GlobalVariables.int_record_id.AsSt ring());

to set the value I am using:

GlobalVariables.int_record_id = some_int_figure_here;


My guess would be that the instance you create is being garbage collected
and/or you are creating a new instance more than once.

If you want such a concept as a "global var" then you should use static
properties rather than instance ones.

e.g.

public class GlobalVariables
{
private static int recordId;

public static int RecordId

{
get {return recordId;}
set {recordId = value;}
}
}

Then you don't need to call the constructor, just address the class (static)
properties directly :

{
GlobalVariables.RecordId = 25;
...
MessageBox.Show(GlobalVariables.RecordId.AsString( ));
}

Joanna

--
Joanna Carter
Consultant Software Engineer
Nov 17 '05 #2
Hi Joanna,

I tried this code:
public class global_var
{
private static int record_id;
public static int int_record_id
{
set {record_id = value;}
get {return record_id;}
}
}
but getting this error:
'global_var.record_id' is inaccessible due to its protection level


Many Thanks,
Jassim Rahma

*** Sent via Developersdex http://www.developersdex.com ***
Nov 17 '05 #3
"Jassim Rahma" <jr****@hotmail.com> a écrit dans le message de news:
u3**************@TK2MSFTNGP12.phx.gbl...
'global_var.record_id' is inaccessible due to its protection level


That's because you are trying to acces the private field, not the public
property.

I used the MS recommended syntax for property and field names, your
non-standard convention has caused you to misread my code example :-)

Joanna

--
Joanna Carter (TeamB)

Consultant Software Engineer
TeamBUG support for UK-BUG
TeamMM support for ModelMaker
Nov 17 '05 #4
Jassim Rahma <jr****@hotmail.com> wrote:
Hi Joanna,

I tried this code:
public class global_var
{
private static int record_id;
public static int int_record_id
{
set {record_id = value;}
get {return record_id;}
}
}
but getting this error:
'global_var.record_id' is inaccessible due to its protection level


Yes, you should be using the property (which is public) rather than the
variable (which is private).

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 17 '05 #5
yes it's working now..
i just wanted to say than you very much.

Many Thanks,
Jassim Rahma

*** Sent via Developersdex http://www.developersdex.com ***
Nov 17 '05 #6

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

Similar topics

6
by: Iain Bishop | last post by:
I'm trying to model objects for the following problem: A building site contains assemblies, each of which can contain other assemblies and/or materials. I have modelled this using a Site...
6
by: Páll Ólafsson | last post by:
Hi I have a problem with the Microsoft.ApplicationBlocks.ExceptionManagement? I can't get it to work in RELEASE mode? If I run the project in debug mode the block works fine but when I run the...
4
by: Angelos Karantzalis | last post by:
Hi guys. I've come across a problem when I tried to serialize a class into xml, only to discover that the parent class's XML Serialization properties weren't included in the output xml. ...
4
by: Leslaw Bieniasz | last post by:
Cracow, 20.09.2004 Hello, I need to implement a library containing a hierarchy of classes together with some binary operations on objects. To fix attention, let me assume that it is a...
10
by: Opa | last post by:
I have tried for two days to solve this problem with no luck. I have a singleton class which has some events declared. When I inherit from this class the events don't seem to come along with it....
0
by: Lokkju | last post by:
I am pretty much lost here - I am trying to create a managed c++ wrapper for this dll, so that I can use it from c#/vb.net, however, it does not conform to any standard style of coding I have seen....
0
by: Lucas, Todd | last post by:
Hello everyone! I'm having a problem with a WebControl that I'm designing for a Menu. I've been at it for about 3 weeks now, and can't seem to get around this problem. So I'm hoping that someone...
7
by: Ryan Shaw | last post by:
I’m having a small problem with inheritance with a hierarchy of classes The example is Class Class Private m_classB as Class Class Class End Clas End Clas
7
by: T.A. | last post by:
Class hierarchy below demonstrates my problem: #include <vector> #include <boost/smart_ptr.hpp> class Fruit { public: virtual ~Fruit() = 0; };
5
by: tshad | last post by:
In VS 2003, I am setting up an abstract class that is setting up classes for each datatype of VB.Net (as well as C#). I am trying to set it up so that most of the work is done in the Abstract...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.