I know this is possible in C++ with pointers but dont know how to do it in C#.
Simplified Sample Code and Comments
//create object A
object A = new object();
//create object B
object B = A;
//create object C
object C = new object();
//I need to change Object A to point to the contents of Object C only using Object B
10 33743 Plater 7,872
Recognized Expert Expert
Why do you need two things pointing to the same object? I've not been able to come up with a use for it.
I know this is possible in C++ with pointers but dont know how to do it in C#.
Simplified Sample Code and Comments
//create object A
object A = new object();
//create object B
object B = A;
//create object C
object C = new object();
//I need to change Object A to point to the contents of Object C only using Object B
Hmm, don't know how to do this directly, however if you create a function and pass it by reference it will exhibit that behaviour.
i.e
//in main or whatever
//create object A
object A = new object();
someFunction(A) ;
.
.
.
private void someFunction(re f object B)
{
object C = new object();
B = C;
}
Now A has been changed to C through B
Not sure if that helps you, I have to admit I haven't come up with a good reason to do it directly in C# yet, though I seem to remember using it more then once in my old C days
-mwalts
Plater 7,872
Recognized Expert Expert
Hmm, don't know how to do this directly, however if you create a function and pass it by reference it will exhibit that behaviour.
i.e
//in main or whatever
//create object A
object A = new object();
someFunction(A) ;
.
.
.
private void someFunction(re f object B)
{
object C = new object();
B = C;
}
Now A has been changed to C through B
Not sure if that helps you, I have to admit I haven't come up with a good reason to do it directly in C# yet, though I seem to remember using it more then once in my old C days
-mwalts
Well, now A has been set to the contents of C, but changing A would not also change C. They don't occupy the same memory, they are still just copies of one another.
If you want to do memory manipulation you have to make the jump into unmanaged code (unsafe code, check msdn on it) and that gets real nasty real fast.
The real situation is I have a field from a datarow that I put into a collection.
Then latter I have the collection but not the datarow(but the datarow still exists). I want to set the datarow field to a new value but feel it will only change the collection to the new data and not the orginal datarow field.
It would be easy if only C# supported pointers to Reference Types
It would be easy if only C# supported pointers to Reference Types
Yeah, but direct memory manipulation would kinda defeat the whole managed sandbox concept period.
For normal reference types you would be able to change their values from the fields located in your collection... for boxed value types and immutable reference types (which are of course the most common in DataRow's) I'm not sure what the behavior would be. Probably won't work since you would have to unbox it to change the value... But it might be worth a try to just change the collections value and see what you get
You might have to put the DataRow into the collection instead of the individual field (or some such work around)
Good luck,
-mwalts
The real situation is I have a field from a datarow that I put into a collection.
Then latter I have the collection but not the datarow(but the datarow still exists). I want to set the datarow field to a new value but feel it will only change the collection to the new data and not the orginal datarow field.
Why don't you want to store a reference to the object itself?
Also, you could implement an event-type system to update the datarow when the value in your collection changes.
Yeah, I had to put the datarow into the collection
I suppose for more generic answer
if you encapsulate a object into another object you can pass the outer object and then change the inner object without loosing the reference?
or something like that
class WrapperObject
{ public TrackedObject obj }
//now you can do this.
WrapperObject A = new WrapperObject() ;
A.obj = new TrackedObject() ;
WrapperObject B = new WrapperObject() ;
TrackedObject C = new TrackedObject() ;
B.obj = C;
//now A.obj = C
Sign in to post your reply or Sign up for a free account.
Similar topics |
by: Pkpatel |
last post by:
Hi,
I keep getting this error every time I try to load
crystalreportviewer on a webform with a dataset.
Here is the error:
--------------------------------------------------------
Server Error in '/Cr_Dataset' Application.
-----------------------------------------------------------
---------------------
|
by: Frawls |
last post by:
Hi,
I get the following error when trying to run a search on my aspx site,
this error only occours if the product im searching for does not
exist. Can anybody explain this please and help me with a solution, i
know its probably simple but im new to the game...Cheers
-----------------------------------------------------------------------
Object reference not set to an instance of an object.
|
by: Martine |
last post by:
Hi there!
I have a problem with programmatically adding user controls to my
mobile webforms. If I load my usercontrol programmatically (in the
Page_Load), the object is instantiated, I have access to the methods
and properties from the Page_Load, no problem there. But as soon as I
want access to the user control from another procedure on the same
page, I get the next error message:
"Object reference not set to an instance of an...
|
by: jw56578 |
last post by:
why am i getting the "Object reference not set to an instance of an
object" error on all page registeration tags in my project.
<%@ Page Language="vb" AutoEventWireup="false"
Codebehind="bid_history.aspx.vb"
Inherits="dnfExchange.marketing_bid_history" %>
|
by: nemo |
last post by:
Hi,
My application works fine on the localhost but spits this error as soon
as I put it on the server. I know this error occurs when an object has
not been instantiated prior to a reference, but why shouldn't it happen
in the localhost?
Here's what the the whole error msg looks like:
| |
by: Adam |
last post by:
We have a web site that uses .vb for the web pages and .cs for a class
module. We are getting the error in .NET 2.0 and VS 2005 beta 2. It does
work with .NET 1.1.
When trying to access a page that needs the class module I get an error on
web site:
Object reference not set to an instance of an object
Here is where the error is:
|
by: eBob.com |
last post by:
I am trying to change some Structures to Classes. The Classes now
look like this ...
Public Class OneAttr
Public AttrName As String
Public Column As String
Public Caption As String
End Class
Public Class OneTable
|
by: Brett |
last post by:
I'm not sure why I keep getting this error, "Object reference not set to an
instance of an object".
Private Function somefunction() as string
Dim MyCurrentClass As New Class1
Try
For i As Integer = 0 To LinkResults.Length - 1
With MyCurrentClass.SqlCmd_Insert_LinkVB
.CommandType = System.Data.CommandType.StoredProcedure
|
by: kalaivanan |
last post by:
hi,
i am a beginner in c#.
i have theoretical knowledge about object, reference and instance.
but i want to know clearly about what is an object, reference and
instance.
can any one help me?
or is there any article which can explain it.
kalaivanan
|
by: livmacca |
last post by:
Hi,
I am new to VB .Net programming and is trying to create a webpage. I encountered the following error and is totally clueless on how to make it work:
==================ERROR==================================
Object reference not set to an instance of an object.
Object reference not set to an instance of an object.
Description: An unhandled exception occurred during the execution of the current web request. Please review the...
|
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...
| |
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,...
|
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...
|
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,...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
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...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
| |
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |