|
From the MSDN documentation for the SortedList.Clone() method:
A shallow copy of a collection copies only the elements of the collection, whether they are reference types or value types, but does not copy the objects that the references refer to. The references in the new collection point to the same objects that the references in the original collection point to.
In contrast, a deep copy of a collection copies the elements and everything directly or indirectly referenced by the elements.
You need to pass a deep copy of each SortedList instance to your set operation methods if you don't want the contents of the original objects to be affected.
Paul Marfleet
|
|
|
|
|
Hi,
Two comments:
1.
yes a and b are passed by value, but the "value" of a reference type is a reference,
so Minus can (and will) change the objects a and/or b point to, but it can not change
the value of a or b themselves.
if you were to add a "ref" keyword, then Minus could not only modify the SortedLists
you pass to it, but it could also change the references themselves (i.e. make the
caller suddenly hold an entirely different SortedList object).
2.
I don't like your Minus method, for two reasons:
2a.
you should preceed it with some comments explaining exactly what functionality it offers.
Yours would be: "calculates and returns the difference of two SortedLists while destroying
one of them".
2b.
you should choose a better method definition, here are two suggestions, pick one:
(A)
<br />
public void Minus(SortedList a, SortedList b)
The comments makes clear a will be modified, and nothing gets returned.
(B)
// calculates the difference a-b b (i.e. returns a SortedList containing those elements
that appear in a but don't appear in b; it does not modify a nor b)
public SortedList Minus(SortedList a, SortedList b)
Now here the code must make sure a is not altered, so a new SortedList must be created;
you could start of this a Clone of a, or with an empty SortedList and add what is
required.
The way you had Minus() was a mix of both, it did return something and did modify
one of its inputs, not a clear situation for the caller.
Hope this helps.
Luc Pattyn [Forum Guidelines] [My Articles]
this months tips:
- use PRE tags to preserve formatting when showing multi-line code snippets
- before you ask a question here, search CodeProject, then Google
|
|
|
|
|
there is an error and icant understand it's meaning
Error "Type or namespace definition, or end-of-file expected "
|
|
|
|
|
Where is your code? There's nothing to work with here.
Seriously, how do you expect anyone to help you if you don't post the code that is causing the error? The more information you provide, the more likely it is that your question will be answered.
Paul Marfleet
|
|
|
|
|
You probably have mismatched curly braces in the file, or, you have an open brace for the namespace definition, but no closing brace.
namespace
{
class
{
properties, methods
{
}
}
class
{
...
}
}
|
|
|
|
|
^ yup, what he said. Go through every open '{' and make sure it closes with a '}' at some point. And i bet you'll find one that doesn't.
My current favourite word is: Waffle
Cheese is still good though.
|
|
|
|
|
Hi Dave,
a new and creative way of using PRE tags?
I do prefer the standard way though (with code, preferably indented).
Luc Pattyn [Forum Guidelines] [My Articles]
this months tips:
- use PRE tags to preserve formatting when showing multi-line code snippets
- before you ask a question here, search CodeProject, then Google
|
|
|
|
|
Whoops! That what you get when you enclose a code section in two closing pre tags.
:->
|
|
|
|
|
Hi All,
I am trying to add data into grid but it doesn't work me. Please can anyone take a look my code and tell me what am doing wrong.
Thanks,
//This data grid has two columns and initially has one row
int countVisitorVarRows = 0;
someforLoop
{
if (newVisitorVarRow == true)
{
countVisitorVarRows++;
dataGridView1.Rows.Add(); //adding second row
dataGridView1.Rows[countVisitorVarRows].Cells[0].Value = str4[i]; //get error here outBound index
dataGridView1.Rows[countVisitorVarRows].Cells[1].Value = str3[i]; //get error here outBound index
}
if (newVisitorVarRow == false)
{
dataGridView1.Rows[0].Cells[0].Value = str4[1]; //Inserting value in first row
dataGridView1.Rows[0].Cells[1].Value = str3[1]; //Inserting value in first row
newVisitorVarRow = true; //if true add new rows
}
} //ENd of someforLoop()
|
|
|
|
|
The code you have posted doesn't make sense. What is someforLoop ? Where is i declared?
If you don't post your actual code, how can you expect anyone to understand what your problem is?
Paul Marfleet
|
|
|
|
|
Hi,
Assume some for loop. for loop has side effect on data grid code if you want you can just ignore the someforLoop().
Thanks,
A.Asif
|
|
|
|
|
For one of the arrays mentioned in the body of your for loop, you must be referencing an element index that does not exist.
Step through your code using the debugger and you should be able to figure out the cause of the problem.
Paul Marfleet
|
|
|
|
|
I think you are interating countVisitorVarRows too early
It is declared 0
then countVisitorVarRows++ before the values are added
you are off by one index number. Do a small trace and you can see this
Hope this helps
I love programming!
|
|
|
|
|
I embeded this object to my aspx page.
<code><OBJECT id="Player" style="WIDTH: 121.92%; HEIGHT: 265px" height="265" width="121.92%" classid="clsid:6BF52A52-394A-11d3-B153-00C04F79FAA6"
>
<PARAM NAME="URL" VALUE="path">
<PARAM NAME="rate" VALUE="1">
<PARAM NAME="balance" VALUE="1">
<PARAM NAME="currentPosition" VALUE="1">
<PARAM NAME="defaultFrame" VALUE="">
<PARAM NAME="playCount" VALUE="10">
<PARAM NAME="autoStart" VALUE="-1">
<PARAM NAME="currentMarker" VALUE="0">
<PARAM NAME="invokeURLs" VALUE="-1">
<PARAM NAME="baseURL" VALUE="">
<PARAM NAME="volume" VALUE="100">
<PARAM NAME="mute" VALUE="0">
<PARAM NAME="uiMode" VALUE="full">
<PARAM NAME="stretchToFit" VALUE="0">
<PARAM NAME="windowlessVideo" VALUE="0">
<PARAM NAME="enabled" VALUE="-1">
<PARAM NAME="enableContextMenu" VALUE="0">
<PARAM NAME="fullScreen" VALUE="0">
<PARAM NAME="SAMIStyle" VALUE="">
<PARAM NAME="SAMILang" VALUE="">
<PARAM NAME="SAMIFilename" VALUE="">
<PARAM NAME="captioningID" VALUE="">
<embed src="path" width="100%" height="223" autostart="1" align="middle" url="path" volume="100"
stretchtofit="100%"> </embed>
</OBJECT>
</code>
path look like D:\song.wma
It can't play this song.Please help me !
nothing
|
|
|
|
|
What has this got to do with C#?
The Web Development forum would be more appropriate for this type of question.
Paul Marfleet
|
|
|
|
|
For a musician C# is the closest thing to D (as in D:\song.wma), only half a tone off.
Luc Pattyn [Forum Guidelines] [My Articles]
this months tips:
- use PRE tags to preserve formatting when showing multi-line code snippets
- before you ask a question here, search CodeProject, then Google
|
|
|
|
|
As is E♭. Although AFAIK there's no such language, so C# will have to do...
Paul Marfleet
|
|
|
|
|
Well there is E[^] and F#[^] and probably a lot more, but they didn't get their own CP forum yet...
Luc Pattyn [Forum Guidelines] [My Articles]
this months tips:
- use PRE tags to preserve formatting when showing multi-line code snippets
- before you ask a question here, search CodeProject, then Google
|
|
|
|
|
Yeah, just because its in an aspx page, doesn't make it a c# problem. And besides, isn't there an ASP .NET section anyways?
My current favourite word is: Waffle
Cheese is still good though.
|
|
|
|
|
I have a C++ dll. I would like to use a C# to access two methods within that dll. What is the best way to do this. I cannot seem to find much information on getting the C# app to talk to the C++ dll.
Is this possible?
If so, how?
Thanks,
cw
|
|
|
|
|
|
I tried placing
[DllImport("My.dll")]
static extern int MakeQUERY(string strTag) ;
Inside my C# class. The call MakeQUERY is in my C++ dll.
But when i try to build this, i get an error:
"The type or namespace name "DllImport" could not be found(are you missing a
using directive or an assembly reference)
|
|
|
|
|
Yeah, that happens a lot.
It typically means you are missing a using directive or an assembly reference
(and probably both).
Have a look at some other program that tries to do what you are trying, i.e.
search CodeProject (or Google) for "DllImport"
Luc Pattyn [Forum Guidelines] [My Articles]
this months tips:
- use PRE tags to preserve formatting when showing multi-line code snippets
- before you ask a question here, search CodeProject, then Google
|
|
|
|
|
You will need to add this one line to able to use DllImport.
using System.Runtime.InteropServices;
Cheers.
------------------------------------------------------------------
Life would have been much easier if I had the source-code!!
|
|
|
|
|
Thanks that got me further.
Now it is throwing a System.EntryPointNotFound error.
My dll looks like this.
#include "stdafx.h"
#include "Mydll.h"
#include <atlcomtime.h>
#include <tchar.h>
#include <vector>
BOOL APIENTRY DllMain( HANDLE hModule,
DWORD ul_reason_for_call,
LPVOID lpReserved
)
{
return TRUE;
}
DLL_API MakeQUERY(LPCSTR strTH, LPCSTR strEH, LPCSTR strSenderID, std::string strPath)
{
}
I added this to my C# declaration
[DllImport("LCIBroker.dll", EntryPoint = "DllMain")]
But it still cannot find the EntryPoint. Is there something that i am missing?
|
|
|
|