|
They might be functionally identical, depending on how you use them, but they aren't the same.
Basically, you have:
triangles -> arrayObject: [ triangle1, triangle2, triangle3 ]
The first block of code would create:
copy -> copyOfArray: [ triangle1, triangle2, triangle3 ]
(copy is a pointer to a new array containing references to the same objects)
The second block would create:
copy -> arrayObject: [ triangle1, triangle2, triangle3 ]
(copy is a pointer to the original array)
Subtle difference, but in the first case, you could sort the copied array independently, and even add and remove elements without touching the original array. In the second case, sorting "copy" would sort "triangles".
(I'm assuming that Triangle is a class, not a struct. If it's a struct, then there's even more of a difference, because the first case would make a completely separate array of independent objects)
EDIT: Silly me, you said it was a class. Last paragraph is irrelevant
|
|
|
|
|
I don't think you have actually created a copy yet. I think you just have a reference to the existing objects. If you truely wanted a copy you would need to do this:
Triangle[] copy = new Triangle[triangles.Length];
for (int i = 0; i != copy.Length; i++)
{
copy[i] = new Triangle();
copy[i] = triangles[i];
}
<./pre>
Otherwise you would have two objects that point to the same thing.
Ben
|
|
|
|
|
Even that wouldn't make an independent copy. You would need some sort of Clone() method, so the inner statement would be:
copy[i] = triangles[i].Clone() as Triangle;
|
|
|
|
|
Right, the code should be:
copy[i] = new Triangle();
copy[i].property1 = triangles[i].property1;
copy[i].property2 = triangles[i].property2;
copy[i].property3 = triangles[i].property3;
...
for as many properties that exist.
If you implement a Triangle.Clone() then you could just do
copy[i] = triangle[i].Clone();
Ben
|
|
|
|
|
This isn't an answer to your question, but this code creates two different types of arrays. The first (triangles) are a list of objects and the second (copy) is a list of reference pointers to the first collection. To do what you are showing there you need to so something like this:
public class Triangle:ICloneable
{
public Triangle(){}
protected Triangle(Triangle clone){ clone.Value = this.Value; }
public object Clone(){return new Triangle(this);}
}
Then you change your loop as such :
for ( blah blah)
{
copy[i] = triangles[i].Clone();
}
As to what things look like on the heap.....I have no idea.
|
|
|
|
|
No, they are not the same.
DenClancy wrote: Triangle[] copy = new Triangle[triangles.Length];
for (int i = 0; i != copy.Length; i++)
{
copy[i] = triangles[i];
}
This will give you a new array, but it contains references to the same objects as the original array.
DenClancy wrote: Triangle[] copy = triangles;
This will only give you another reference to the same array.
---
single minded; short sighted; long gone;
|
|
|
|
|
Hi,
I am using Windows Indexing services via the OleDB Driver.
Now everything works good, till i am to pass (") double quotes into the query
Sample query to pass
SELECT path FROM SCOPE() WHERE Matches("test*");
Now after all the process the VS 2005 just appends \ to my query
SELECT path FROM SCOPE() WHERE Matches(\"test*\");
"Mess with the Best, Die like the rest"
|
|
|
|
|
Passing queries is a real bad idea to being with because of sql injection issues. Still to fix your problems you just need more double quotes. I believe your query will work if it is like this:
SELECT path FROM SCOPE() WHERE Matches("""test*""");
Hope that helps.
Ben
|
|
|
|
|
Thx for the replying
Below is the original c# code
queryString = queryString + " MATCHES(""" + strExactPhrase.ToString() + """)";
* *
*'s are the points where i am getting an error "; expected" in VS 2005
Thank you!
"Mess with the Best, Die like the rest"
|
|
|
|
|
Does this work:
queryString = queryString + " MATCHES(\"" + strExactPhrase.ToString() + "\")";
Ben
|
|
|
|
|
I think you're mixing up C# and VB.NET here. VB.NET uses pairs of quotes ("" -> "), while C# uses backslash-escapes (\" -> "). If you print the string to the debugger or watch windows, you WILL see the escape codes in C#, but that's not actually in the string.
So basically, stick with the original version, using \" to represent a double-quote, and don't worry if you see the backslash when debugging.
|
|
|
|
|
You are right. You know I think I might have also gotten it mixed up with the single quote. You can have problems with that as well.
Ben
|
|
|
|
|
The single quote shouldn't cause you any problems in C#, since it has no special meaning inside double-quotes. That's only used to signify a character instead of a string.
|
|
|
|
|
Really, try a query that searches for a lastname of o'leary. You can certainly have some problems with that. I have had more problems with this because of some dynamic sql creation. I have some stored procedures where you pass in some xml that is a parameter list. The xml is read into a table and then those parameters are used to dynamically create a specific seach query. In that case you for sure can have problems passing in single quotes.
Ben
|
|
|
|
|
Ah, well that has to be a problem with the SQL provider, not with C#... C# will happily pass single-quotes into a string, but maybe the data source has trouble parsing it out.
|
|
|
|
|
Right, I am sorry if I was saying .net would have a problem. The problem is on the sql server side.
Ben
|
|
|
|
|
Thx a lot
The thing got resolved, it was the OleDB Data Provider's dll that needed to be re-installed
Thank you!
"Mess with the Best, Die like the rest"
|
|
|
|
|
Hello everyone,
I ran into this error, which im not sure whats wrong.
On my form1.cs, i have this code:
SyntaxHighlightingTextBox shtb;<br />
public form1<br />
{<br />
InitializeComponent();<br />
shtb = new SyntaxHighlightingTextBox();<br />
shtb.ContextMenu = MyContextMenu;<br />
}
When i try to build the solution, i get the following error:
Cannot implicitly convert type 'System.Windows.Forms.ContextMenuStrip' to 'System.Windows.Forms.ContextMenu'
I don't understand, i have a fully working context menu, but when i try to add that context menu inside shtb (SyntaxHighlighting RichTextBox), im getting that error.
Anyone can help me figure this one out please?
|
|
|
|
|
Your trying to add a ContextMenuStrip when you need to be adding a ContextMenu.
Either change your ContextMenuStrip to a ContextMenu or change your SyntaxHighlightingTextBox to inherit the textbox class in the .net 2.0 framework
|
|
|
|
|
Thanks allot for your advice,
I changed
shtb.ContextMenu = MyContextMenu;
To
shtb.ContextMenuStrip = MyContextMenu;
Now its working
|
|
|
|
|
DataView defaultView = new DataView();
//this table has three fields...
defaultView = dsCorrelationsIndices.Tables["CorrelationsIndicesValues"].DefaultView;
//one row is returned...
defaultView.RowFilter = dsCorrelationsIndices.Tables["CorrelationsIndicesValues"].Columns["Index1Name"].ColumnName + " = '" + strIndex1Name + "' AND " + dsCorrelationsIndices.Tables["CorrelationsIndicesValues"].Columns["Index2Name"].ColumnName + " = '" + strIndex1Name + "'";
I would like to get the value in the third column
//?????????????????
string v = how do I get the third value from the filtered dataset??
Thanks
|
|
|
|
|
defaultView[rowNumber][2].ToString();
or
defaultView[rowNumber]["ColumnName"].ToString();
|
|
|
|
|
Hi,
This ia quite an urgent problem I have here, my project is slipping too far and I have a racing festival to launch my code for very soon so any help would be appreciated!
I have the following code, which is broken down into a more managable form, during the debugging process:
1: object o=new MembershipLevel().FindByItemCode(itemCode);
2: MembershipLevel membershipLevel=o as MembershipLevel;
Now, line 1 successfully extracts a record from the database and populates o accrdingly, with a MembershipLevel object. It's great, I can see it's the correct record, and it is the correct type.
Line 2 is used to cast the type into something so I can get at the data inside it. However, this cast fails. In its original shorthand form of { MembershipLevel membershipLevel=(MembershipLevel)o }, this threw an exception InvalidCast excpetion saying "Cannot cast MembershipLevel into MembershipLevel", so it knows the types are same, but it will not cast it!
MembershipLevel has been loaded via reflection from the web site bin folder. Interestingly, a previous object has also been loaded using the same method and that works fine. Also, this code is in the same assembly. The assembly is present and correct.
Any help appreciated
|
|
|
|
|
My best guess would be that you have two classes with the same name, but in different namespaces. After step 1, try comparing the following two statements, and see if they match:
o.GetType().ToString()
typeof(MembershipLevel).ToString()
Alternatively, it might be the same type, but a different signature. You said you're loading it through reflection, so the file you're loading might have an older version of "MembershipLevel". If the signatures don't match, you can't cast it.
|
|
|
|
|
Thanks for your reply.
The namespaces are identical, I removed them from the code I posted for clarity. (They are quite deep and had company names in)
For your second point, this does seem likely, but I am quite sure it is loading and debugging from the same assembly. I can cast fine in the debugger immediate window, just not in the code. The file is in the bin folder in the web site, where else could it be getting the class? It is in a class library.
HOw can I tell? Particularly if the debugger casting works fine?
|
|
|
|