|
Hey,
I'm a little confused with the definition of a shallow copy. From the definitions I can find online, I get that reference types get copied, but not the value they refer to. In other words, they should point to the same value. However, when I test this, I can assign a new value to a reference type in either the original or the copy, and the value in it's counterpart won't change.
This is the code I used to test this:
Sub Main()
Dim list1 As New List(Of Spam)
list1.Add(New Spam(1))
list1.Add(New Spam(2))
list1.Add(New Spam(3))
Dim list2 As List(Of Spam)
list2 = list1.GetRange(0, list1.Count) ' this should make a shallow copy
list2.Item(1) = New Spam(5)
For Each s As Spam In list1
Console.Write(s.ToString & " ")
Next
Console.ReadKey()
End Sub
Private Class Spam
Public Sub New(ByVal v As Integer)
value = v
End Sub
Dim value As Integer
Public Overrides Function ToString() As String
Return value.ToString
End Function
End Class
The output of this code is "1 2 3", and not "1 5 3", which I'd expect from the definition of a shallow copy.
Please un-confuse me here
Cheers!
Jeroen De Dauw
---
Forums ; Blog ; Wiki
---
70 72 6F 67 72 61 6D 6D 69 6E 67 20 34 20 6C 69 66 65!
|
|
|
|
|
Dag Jeroen,
While you write
jeroen de dauw wrote: I can assign a new value to a reference type
that does not really make sense (a type is a type, a type does not have a value at all); and it is not what list2.Item(1) = New Spam(5) does. Yes list2 is a reference type (it is an object, not a value type), as lists and arrays are collections holding things of a single type (either value types of reference types themselves). In this case, the list holds reference types, i.e. references to Spam instances.
What your statement does is it overwrites an existing reference by a reference to a new object. So none of the existing Spam objects is being modified.
As your use of the terminology isn't correct, this suggests you got a few things confused.
A shallow copy copies everything: the data in value types and the data in a reference type. The trick is a reference type only holds a reference (think of it as a pointer), and that is what gets copied. The thing (object) it points to is not being copied or cloned, so the old and new pointers now point to one and the same thing.
To prove, or rather disprove, your statement about shallow copies, you should add a Value property to the Spam class, then execute list2.Item(1).Value = 17 and watch how both lists reflect the change, as you now would have changed an existing object, where both lists are referring to.
|
|
|
|
|
Well, now you said it, it seems so obvious
Thanks a lot for making me understand my error
Jeroen De Dauw
---
Forums ; Blog ; Wiki
---
70 72 6F 67 72 61 6D 6D 69 6E 67 20 34 20 6C 69 66 65!
|
|
|
|
|
First timer with VB and .Net
In the following code I get the displayed error when I execute the objOS.Get. I'm executing on an XP Pro SP3 and have all updates installed. I would assume
I'm missing something but WHAT? Any help is appreciated.
Dim objMgmt As ManagementObject
Dim objOS As New ManagementObjectSearcher("SELECT * FROM Win32_OperatingSystem")
For Each objMgmt In objOS.Get
A first chance exception of type 'System.Runtime.InteropServices.COMException' occurred in System.Management.dll
An unhandled exception of type 'System.Runtime.InteropServices.COMException' occurred in System.Management.dll
Additional information: The dependency service does not exist or has been marked for deletion. (Exception from HRESULT: 0x80070433)
TIA
Tony Teveris
Gerber Scientific Products
Senior Software Engineer
Phone: 860 648 8151
Fax: 860 648 8214
83 Gerber Road West
South Windsor, CT 06074
|
|
|
|
|
I want to work with Memory Mapped Files. That's why I just installed the .Net framework 4.0 beta 2.
But now I can't find the System.IO.MemoryMappedFiles dll.
|
|
|
|
|
That's because there is no such .DLL.
If you read the documentation on the System.IO.MemoryMappedFiles namespace, you'll see that there is no need to import a .DLL because that namespace is exposed by the System.Core assembly, which every .NET app already uses.
|
|
|
|
|
Hi all,
Dose any one know about documentation oF MSPastry Library under MSDN that could be utilized in C# code?
thnaks to you all in advances
|
|
|
|
|
|
After working in Visual Studio 2008 with SP1 on my application, everything works sweet with visifire charts.
I then create an install for my application and deploy it to a seperate machine. Charts do not work, and we get system.exception with Eventype:clr20r3
Can visifire be run without VS 2008? I don't expect to install VS 2008 SP1 on every install instance of my app with visifire.
I'm using WPF, and am creating the chart dynamically through code. I'm using the latest stable/non-beta version of visifire, v2.1
|
|
|
|
|
You've been told about this, now please stop.
"WPF has many lovers. It's a veritable porn star!" - Josh Smith As Braveheart once said, "You can take our freedom but you'll never take our Hobnobs!" - Martin Hughes.
My blog | My articles | MoXAML PowerToys | Onyx
|
|
|
|
|
Dude. HYou've already been told that you should be waiting on an answer from VISIFIRE.
The chances of someone here using that package are very very low. If you have specific questions about a vendor's product, the best place to ask is the vendor or a vendors support forms.
You've got about the same chance of getting an answer on that package here as you do just going outside and asking the first person who walks by.
|
|
|
|
|
Have you tried the VISIFIRE forums. I just did a quick search on there and found a post immediately saying .Net 3.5 SP1 is required on the deployment machine.
|
|
|
|
|
Hi, I have already visual studio 2008 in my machine and then I installed vb6. Now the problem is when I use javascript debugging through the debugger keyword, its open the VB6 environment instead of Visual Studio. How to resolve this problem
Pankaj
|
|
|
|
|
Hi, I m using DataGridView in c#.net, can anyone help me with the code to obtain the following.
------------------------------------------------------------|
Student Details | Course Details |
------------------------------------------------------------|
Name | Address | Name | Code No |
------------------------------------------------------------|
aaa | India | CS | 123 |
------------------------------------------------------------|
|
|
|
|
|
|
Can anyone tell me with code in vb.net how to get email notification when client has opened the email sent to him and which client and on which link and how many time he had clicked in the email sent to him
|
|
|
|
|
I have a board of hexagons I've created on the screen and an image (icon) that I want to fill a hexagon with when it is clicked. I have the code to figure out which hex was clicked on but I can't figure out how to get the image into the hex. My attempt:
Image hexImage = new Bitmap(@"IconH.ico");
TextureBrush hexBrush = new TextureBrush(hexImage);
texture.WrapMode = System.Drawing.Drawing2D.WrapMode.Clamp;
bitmapGraphics.FillPolygon(hexBrush, board.Hexes[i, j].Points);
But this just puts the image in the upper right of the board and clips it so the image doesn't show unless I happen to click on the upper right hex. If I set WrapMode to allow tiling I get pieces of the image in the hex I click on but it doesn't line up. I'd like to be able to pass x and y coordinates to FillPolygon to tell it center the image on the polygon but none of the overloaded methods allow it. I'd also like to be able to resize the image to fit the hex since I want to allow the user to change the size of the hexes, but one problem at a time.
Jeff Wilson
|
|
|
|
|
Sorry to respond to my own post but even though I've been struggling with this for a couple days it just occurred to me (less than an hour after posting) that the answer might lie in TextureBrush instead of FillPolygon. It looks like the bounded rectangle that you can specify in the TextureBrush constructor might solve my problem, and the TranslateTransform method looks interesting too. I'll play around with it for a while and let you know if that solves it. If I'm on the wrong track, please feel free to respond at any time.
Jeff Wilson
|
|
|
|
|
I'm not really sure if this is even possible. Mapping the printer is no problem but my first thought is that it would not be possible from a webpage, security restrictions and all. As far as I can see it would require an ActiveX, or similar, control.
"By using the printing portal site and indicating their location (by drill down or similar) users would be presented with a list of nearby printers for their use. Clicking a printer should create a permanent mapping to the queue for their workstation. A set as default option would also be required."
I know the language. I've read a book. - _Madmatt
|
|
|
|
|
Mark Nischalke wrote: a list of nearby printers for their use
Sounds like a LAN, not a webpage on the internet. Which of those two are you targeting?
I are Troll
|
|
|
|
|
It was a request from a client. Not sure really what they are thinking at this point
I know the language. I've read a book. - _Madmatt
|
|
|
|
|
Printing over a network is easy. Printing over the internet usually isn't. That doesn't mean that it's impossible, off course;
Microsoft Technet on Internet Printing[^]. You might want to check with your client, I'm guessing that he/she wants to be able to print from every internet-enabled apparatus.
I are Troll
|
|
|
|
|
From what I was able to gather from them, they don't want internet printing, they want to assign a printer on the local machine from a webpage, specifically from a webpart in a SharePoint portal site.
I know the language. I've read a book. - _Madmatt
|
|
|
|
|
Hi,
am using a dll in my web project ("Owc11.dll")
Before upgrading our production server (32 bit) it was working fine. So, recently
our production server has been upgraded to 64 bit. So, while running the
application one error throwing like this:
"retrieving the COM class factory for component with CLSID {0002E55D-0000-0000-C000-000000000046} failed due to the following error: 80040154"
Anybody could you please help me asap.
These much ways i have tried,
1. dll registered in GAC also available in regedit.
2. Enabled 32 bit appln (WOW64) on 64 bit application pool by using .net command prompt. But i have 64 applns in the server. So left this method. (IIS won't support 32/64 bit applns at the same time).
3. Created Wrapper DLL and used by pre-binding method (act like interface b/w 32 bit DLL and 64 bit appln)
4. Handlers also used.
thanks in advance .
Thanks & Regards,
Jeneesh K. Velayudhan
modified on Tuesday, December 22, 2009 9:47 PM
|
|
|
|
|
This normally means that it can't find the COM class factory. In other words, it can't find the appropriate DLLs. Open up regedit, and have a look for that CLSID in HKCR\CLSID.
"WPF has many lovers. It's a veritable porn star!" - Josh Smith As Braveheart once said, "You can take our freedom but you'll never take our Hobnobs!" - Martin Hughes.
My blog | My articles | MoXAML PowerToys | Onyx
|
|
|
|