HighTechTalks DotNet Forums  

Accessing a variable by reference in c#

Dotnet Framework (CLR) microsoft.public.dotnet.framework.clr


Discuss Accessing a variable by reference in c# in the Dotnet Framework (CLR) forum.



Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old   
Christopher
 
Posts: n/a

Default Accessing a variable by reference in c# - 07-07-2003 , 09:37 AM






Hi all,

I am trying to store a reference to a variable in my data
provider class
but cannot save a reference to it. Can anyone help me?

I would like this code to allow me to store any field by
referenece so that
it's contents can be written to using the Value property.

Code sample:
============
public class MyField
{
private string strFieldName;
private object objValue;

public string FieldName {set{strFieldName=value;}get
{return(strFieldName);}}
public object Value {set{objValue=value;}get{return
(objValue);}}

public SqlField(string pFieldName,
ref object pObject) /* THIS LINE DOES NOT WORK AT
POINT REF */
{
strFieldName=pFieldName;
objValue=pObject;
}

Then in the program it is called using:
=======================================
int y=0;
MyField m = new MyField("id", ref y);
y=26;

Results wanted:
===============
m.Value is 0,
m.Value is 26 when y is set to 26

Please note that I don't always want to store an integer,
it maybe a string
or other object.

Thanks in advance
Chris


Reply With Quote
Reply




Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.