|
humblepgmr wrote: aList.sort(); //this doesn't work
Obviously. The Sort method doesn't have any clue how to compare and sort your objects. So, you have to provide an IComparer[^] implementation to compare two of your objects and return the result of the compare.
|
|
|
|
|
Talking to yourself again?
Deja View - the feeling that you've seen this post before.
|
|
|
|
|
I know. Workin' for the government is drives you to drink. You end up in a dark corner babbling to yourself like an idiot. It'll pass in a few short weeks.
|
|
|
|
|
I have an class defined as below. This class has an integer value assigned to it named initiative. For the purposes of this post this value can be from 1 to 3.
<br />
public class Unit : IComparable<br />
{<br />
....<br />
public int Initiative = ....;<br />
<br />
public int CompareTo(object obj)<br />
{<br />
if (obj is Unit)<br />
{<br />
Unit u = (Unit)obj;<br />
return Initiative.CompareTo(u.Initiative);<br />
}<br />
throw new ArgumentException("object is not a Unit"); <br />
}<br />
}<br />
I have 10 of these objects defined in an array. I want to be able to sort the array by this initiative value however everytime I run a sort I want the object with equal value to be randomly organised. For example if I run sort once:
object - initiative
A - 1
B - 1
C - 1
D - 2
E - 2
F - 2
G - 3
H - 3
I - 3
J - 3
If I run it again, I may get:
object - initiative
B - 1
A - 1
C - 1
F - 2
D - 2
E - 2
G - 3
J - 3
H - 3
I - 3
How can I achieve this using IComparable?
Thanks in advance.
|
|
|
|
|
if (obj is Unit)
{
Unit u = (Unit)obj;
if (obj == this) return Random.Next(2) - 1;
return Initiative
someting like that
Christian Graus - Microsoft MVP - C++
"I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
|
|
|
|
|
Christian Graus wrote: (obj == this)
This would compare references. Override == operator or write: (obj.Initiative == this.Initiative) .
Greetings - Gajatko
Portable.NET is part of DotGNU, a project to build a complete Free Software replacement for .NET - a system that truly belongs to the developers.
|
|
|
|
|
Sure - I was really just trying to show how to introduce some randomness. But thanks for adding this, it does make the overall answer more correct.
Christian Graus - Microsoft MVP - C++
"I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
|
|
|
|
|
PLZ I Want to used xml file as database(how to add,update,delete and Search)
i will make the database program
using interface C# and DataBase <xml>
thanks.
|
|
|
|
|
You can want all you want. It's not going to change the fact that XML is NOT a database. You cannot use SQL statements to navigate through the tables. You have to use the various XML methods to modify your tables, but XML is very inefficient at it.
|
|
|
|
|
Dave Kreskowiak wrote: You can't want all you want.
I don't think that is what you meant... :P
Christian Graus - Microsoft MVP - C++
"I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
|
|
|
|
|
Whoops. I knew that didn't look right when I posted it...
|
|
|
|
|
Unless your data set is very small, this smells of disaster. XPath is how you search XML. The DOM via the XMLDocument class is how you interact up add/update/delete/search.
Christian Graus - Microsoft MVP - C++
"I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
|
|
|
|
|
If You really want you can.Once again Is that you really want to do.
check DataSet members ReadXML()/WriteXML()
load XML Store to Dataset using ReadXML ( on Application Initialization )
Manipulate ( add/delete etc.. ) this DataSet during application life cycle.
On ApplicationExit use WriteXML.
"Sometimes solutions will be as simple as 1=1 , confused right "
By
BAIJUMAX
|
|
|
|
|
how to deploy a project which expires after one month.means how to make a demo application
how to give company name ,version when deployinga project.
monu_khan in trouble
|
|
|
|
|
You can't do that via your deployment, you have to create a demo version. And, you need to ask yourself who your market is. A simple way is just to store the install date somewhere, and check if 30 days have passed. People can get by this by setting their clock back, or just by decompiling your app and removing the check. If your clients are likely to do that, then it's a whole lot harder, but a basic 30 day check is trivial to do.
Christian Graus - Microsoft MVP - C++
"I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
|
|
|
|
|
Do not use the word 'urgent' in your post, it is considered rude. It only will anger most people. Most members on this site come here on their own free-will and are not obligated to replying with rude requests like 'urgent'
"Find it your bloody self - immediately!" - Dave Kreskowiak
|
|
|
|
|
Well said.
Deja View - the feeling that you've seen this post before.
|
|
|
|
|
Needed to get somewhat verbose instead of the typical Don't say urgent style of posts.
"Find it your bloody self - immediately!" - Dave Kreskowiak
|
|
|
|
|
Hello,
I have a class without a namespace. The main reason why I don't have a namespace in that class is because I use that class in all my applications.
Now I like to update application settings in that class, but I don't like to use the following line in that class:
using ApplicationNamespace.Properties;
Is there a way where i can reference that up to my class?
|
|
|
|
|
You may think that your class is not contained in a namespace, but it IS in one. The default name for a namespace is the name of the project.
|
|
|
|
|
Well, that's the point, i would like to be able to copy the class everywhere without changing/adding the projects namespace into the class and still updating the namespace's settings.
Maybe it is impossible, but i like to ask.
|
|
|
|
|
Yeah, it is, you can't change the namespace your code is in.
Christian Graus - Microsoft MVP - C++
"I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
|
|
|
|
|
Like Christian said, you can't do that. The namespace is part of the fully qualified name of the class. Changing it is out of the question.
The only way you can use this class in other projects is to add a reference to it's .DLL. Importing the namespace is optional, but it saves you from having to type the full namespace/class path in your other project's code.
|
|
|
|
|
|
Check 'Ignore HTML tags in this message' to post your XML.
Paul Marfleet
|
|
|
|