|
Try a google search.[^]
I Love T-SQL
"Don't torture yourself,let the life to do it for you."
If my post helps you kindly save my time by voting my post.
|
|
|
|
|
I love it, I thought I'll take a look at the results for this one. 1st link is to CP, straight back to this message
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
Yeah,it's intersing result search
I Love T-SQL
"Don't torture yourself,let the life to do it for you."
If my post helps you kindly save my time by voting my post.
|
|
|
|
|
Blue_Boy wrote: intersing result search
Latest page update phenomenon is the reason that is causing Google to bring this page on top.
Vasudevan Deepak Kumar
Personal Homepage Tech Gossips
The woods are lovely, dark and deep,
But I have promises to keep,
And miles to go before I sleep,
And miles to go before I sleep!
|
|
|
|
|
Hallo Board,
I am facing a problem with a self-written Equal Operator on a list<> class with own classes inside the list.
I want to compare lists thus I redefined the == Operator:
public override bool Equals(object obj)<br />
{<br />
UserList compUserList = (UserList)obj;<br />
foreach (PersonDataSet user in compUserList.list)<br />
{<br />
....
return true;<br />
}<br />
return false;<br />
}<br />
The problem is now that I checked in my code before writing the own operator if a special UserList has already been created by
if (testUserList != null) .
Now I get a NullPointer exception wenn testing for 'null'.
This is understandable, but does anyone have an idea how to solve the problem? Maybe a different check to test if an object has been created? Or is a check like this not good at all?
Thanks for your replies!
Regards
Chris
modified on Monday, July 13, 2009 5:32 AM
|
|
|
|
|
The operator == is not the same as the Equals method. Even the result can sometimes differ (as is the case with NaN's in float comparisons)
If you want to overload the == operator you would have to overload it.
|
|
|
|
|
I thought these operators were the same?
but I declared
public static bool operator ==(UserList userlist1, UserList userlist2)
{
return (userlist1.Equals(userlist2));
}
as well.
So these operators should be correctly defined.
Or am I wrong?
|
|
|
|
|
That should work, although you may be a good idea to test userlist1 for being null before calling Equals on it to avoid a nullref when testing null == userlist2
oh and you'd have to define != as well but the compiler will tell you that
|
|
|
|
|
chrisx51 wrote: testUserList
Does object testUserList exists? Where did you declare it?
Inside your function I can't see any object named testUserList.
I Love T-SQL
"Don't torture yourself,let the life to do it for you."
If my post helps you kindly save my time by voting my post.
|
|
|
|
|
testUserList is being declared in the full programm when a new userlist is being created in another function.
But in the code I need to check a UserList has already been created thus i use if (testUserList != null to check if it really exists.
But my redefined function doesnt like a 'null' as parameter...
|
|
|
|
|
From past experience, overloading == and != on a class is generally not a good idea because of the possiblity of it being null.
It works great for structs, but that can bring other problems!
DaveBTW, in software, hope and pray is not a viable strategy. (Luc Pattyn) Visual Basic is not used by normal people so we're not covering it here. (Uncyclopedia) Why are you using VB6? Do you hate yourself? (Christian Graus)
|
|
|
|
|
Do you have a better idea to check the equality of an own List<>?
Shall I create a completely new function like ownEqualityCheck(UserList userlist...); ?
|
|
|
|
|
I've just had another look at this. It seems that by converting your class instances to objects, you can do a null check. e.g.
public class Test
{
private int internalValue;
public Test(int value)
{
internalValue = value;
}
public static bool operator ==(Test test1, Test test2)
{
object o1 = test1;
object o2 = test2;
if (o1 == null || o2 == null)
return (o1 == null && o2 == null);
return test1.internalValue == test2.internalValue;
}
public static bool operator !=(Test test1, Test test2)
{
return !(test1 == test2);
}
}
DaveBTW, in software, hope and pray is not a viable strategy. (Luc Pattyn) Visual Basic is not used by normal people so we're not covering it here. (Uncyclopedia) Why are you using VB6? Do you hate yourself? (Christian Graus)
|
|
|
|
|
Hi,
thank you very much for your hint!
I implemented it and it just works fine!
Regards,
Chris
|
|
|
|
|
Thsi may be silliy, but your operator overload code doesn't do any checking to see if one of the object passed in is null or not before trying to use it. You should be check to see if you actually have an object, handle the case where the object is null , then check to see if it is a valid object type to compare against, ...
|
|
|
|
|
So your advice is to use overloading the == Operator but with additional checks like:
public static bool operator ==(UserList userlist1, UserList userlist2)
{
if (userlist1 == null) return false;
....
}
But by doing so i repeatedly call the ==-Operator recursivly. Is this ok? I believe i get the NullPointerExcception as well.
--> ok I tested it and I get a StackOverflowException. Thats sort of what I Expected.
modified on Friday, July 10, 2009 5:53 AM
|
|
|
|
|
How can I load an XML Document to an ObservableCollection class that preserves the XML tree structure?
My xml looks like this:
<?xml version="1.0" encoding="utf-8" ?>
<string xmlns="http://none.none.none/webservices">
<TREENODES xmlns:sql="urn:schemas-microsoft-com:xml-sql">
<TREENODE code="1" text="None" >
<TREENODE code="2" text="America" >
<TREENODE code="16128" text="AUTOS">
<TREENODE code="ATO" text="ATO" />
<TREENODE code="ATO" text="ATO" />
</TREENODE>
</TREENODE>
</TREENODE>
<TREENODE code="11" text="None" >
<TREENODE code="21" text="America" >
<TREENODE code="3" text="AUTOS">
<TREENODE code="ATO44" text="ATO5" />
</TREENODE>
</TREENODE>
</TREENODE>
</TREENODES>
</string>
|
|
|
|
|
Depends on what you're loading it for. What is the consumer of the object?
You can make something like:
public class TreeNode
{
public string Code { get; set; }
public string Text { get; set; }
public List<TreeNode> Children { get; set }
public TreeNode()
{
Children = new List<TreeNode>();
}
}
In both WPF and Silverlight you could databind with a hierarchal template.
Again, it all depends on how/what/why you are using it.
You can populate the tree using LINQ to XML.
Jeremy Likness
http://csharperimage.jeremylikness.com/
|
|
|
|
|
So what would be the LINQ?
Thanks in Advance
|
|
|
|
|
Also this class it seems that will create a simple list. Not a tree like the XML.
|
|
|
|
|
It will create a hierarchal object graph. Something like this would populate it:
public TreeNode Populate(XDocument doc)
{
var retVal = (from treeNode in doc.Descendants("TreeNode")
select new TreeNode()
{
Code = treeNode.Attribute("Code").Value,
Text = treeNode.Attribute("Text").Value
}).SingleOrDefault();
retVal.Children = _Recurse((from treeNode in doc.Descendants("TreeNode")
select treeNode).SingleOrDefault());
return retVal;
}
private static List<TreeNode> _Recurse(XContainer root)
{
List<TreeNode> retVal = new List<TreeNode>();
var children = from child in root.Descendants("TreeNode") select child;
foreach(var child in children)
{
TreeNode node = new TreeNode
{
Code = child.Attribute("Code").Value,
Text = child.Attribute("Text").Value,
Children = _Recurse(child)
};
retVal.Add(node);
}
return retVal;
}
Jeremy Likness
http://csharperimage.jeremylikness.com/
|
|
|
|
|
Have you seen the Linq exception
"Sequence contains more than one element"? It comes from Populate.
|
|
|
|
|
it was the FirstOrDefault not SingleOrDefault.
Will this work if I change the class from List to ObservableCollection?
Thanks a bunch.
|
|
|
|
|
Hi All,
I am developing a Windows Service application.
It connects the SQL server for data.It uses the Integrated security = true for the connection string.
My serivice is running fine while the Service and SQL running in same NT domain.
It throws an error for (cross domain) while service in Domain1 and SQL server in Domain2.
Is there any way to resolve the issue without changing the Integrated security and passing the User name and password. Does it make sense?.
Thanks in advance.
Regards,
Arafath.
|
|
|
|
|
I am having some weird panel issues. In my program I have multiple panels of different contents. For example there is a welcome screen, the user clicks next and the welcome screen is not visible and the next screen is.When the screens are changed with the next button they work fine.
Here is where the problem is... However if I want to change them from a seperate thread, the panel is visible but the contents of the panel are not. I am calling the same function to change the panels' visiblity (and the contents have all been set to visible). I have made sure that all labels were changed using the invokerequired/settextcallback stuff. What am I forgetting?
|
|
|
|