C# Client Server Application on WPF IDE
-
Hello Everyone I have created a Client/Server application on C# on WPF IDE and I have a little problem on my UserClient property class... Within this class I have a method called:
public override bool Equals(object obj)
{
UserClient temp = obj as UserClient;
if (temp != null)
{
return (userId == temp.userId);
}
if (temp != null)
{
return (userPass == temp.userPass);
}
return false;
}The problem I'm having is: The class UserClient is highlighted with a green line under-neath where when I place MouseOver it sas: UserClient overrides Object.Equals but does not override Object.GetHashCode Here is the entire UserClient class code:
using System;
using System.Collections;
using System.Collections.Generic;
using System.Data;
using System.Diagnostics;namespace DtposClient
{
public class UserClient
{
// User Client Global variables
// ====================================
private string UserFullName;
private string UserAccessLevel;
private int UserId;
private int UserPassword;public string fullName { get { return UserFullName; } set { UserFullName = value; } } public string accLevel { get { return UserAccessLevel; } set { UserAccessLevel = value; } } public int userId { get { return UserId; } set { UserId = value; } } public int userPass { get { return UserPassword; } set { UserPassword = value; } } public override bool Equals(object obj) { UserClient temp = obj as UserClient; if (temp != null) { return (userId == temp.userId); } if (temp != null) { return (userPass == temp.userPass); } return false; } public UserClient(string fullNam, string aLevel, int usId, int pass) { fullName = fullNam; accLevel = aLevel; userId = usId; userPass = pass; } }
}
Could someone please help me crack this problem.... thanks in advance kind regards lapeci
-
Hello Everyone I have created a Client/Server application on C# on WPF IDE and I have a little problem on my UserClient property class... Within this class I have a method called:
public override bool Equals(object obj)
{
UserClient temp = obj as UserClient;
if (temp != null)
{
return (userId == temp.userId);
}
if (temp != null)
{
return (userPass == temp.userPass);
}
return false;
}The problem I'm having is: The class UserClient is highlighted with a green line under-neath where when I place MouseOver it sas: UserClient overrides Object.Equals but does not override Object.GetHashCode Here is the entire UserClient class code:
using System;
using System.Collections;
using System.Collections.Generic;
using System.Data;
using System.Diagnostics;namespace DtposClient
{
public class UserClient
{
// User Client Global variables
// ====================================
private string UserFullName;
private string UserAccessLevel;
private int UserId;
private int UserPassword;public string fullName { get { return UserFullName; } set { UserFullName = value; } } public string accLevel { get { return UserAccessLevel; } set { UserAccessLevel = value; } } public int userId { get { return UserId; } set { UserId = value; } } public int userPass { get { return UserPassword; } set { UserPassword = value; } } public override bool Equals(object obj) { UserClient temp = obj as UserClient; if (temp != null) { return (userId == temp.userId); } if (temp != null) { return (userPass == temp.userPass); } return false; } public UserClient(string fullNam, string aLevel, int usId, int pass) { fullName = fullNam; accLevel = aLevel; userId = usId; userPass = pass; } }
}
Could someone please help me crack this problem.... thanks in advance kind regards lapeci
-
Hello Everyone I have created a Client/Server application on C# on WPF IDE and I have a little problem on my UserClient property class... Within this class I have a method called:
public override bool Equals(object obj)
{
UserClient temp = obj as UserClient;
if (temp != null)
{
return (userId == temp.userId);
}
if (temp != null)
{
return (userPass == temp.userPass);
}
return false;
}The problem I'm having is: The class UserClient is highlighted with a green line under-neath where when I place MouseOver it sas: UserClient overrides Object.Equals but does not override Object.GetHashCode Here is the entire UserClient class code:
using System;
using System.Collections;
using System.Collections.Generic;
using System.Data;
using System.Diagnostics;namespace DtposClient
{
public class UserClient
{
// User Client Global variables
// ====================================
private string UserFullName;
private string UserAccessLevel;
private int UserId;
private int UserPassword;public string fullName { get { return UserFullName; } set { UserFullName = value; } } public string accLevel { get { return UserAccessLevel; } set { UserAccessLevel = value; } } public int userId { get { return UserId; } set { UserId = value; } } public int userPass { get { return UserPassword; } set { UserPassword = value; } } public override bool Equals(object obj) { UserClient temp = obj as UserClient; if (temp != null) { return (userId == temp.userId); } if (temp != null) { return (userPass == temp.userPass); } return false; } public UserClient(string fullNam, string aLevel, int usId, int pass) { fullName = fullNam; accLevel = aLevel; userId = usId; userPass = pass; } }
}
Could someone please help me crack this problem.... thanks in advance kind regards lapeci
That's easy. Whenever you override
Equals
, you are required to overrideGetHashCode
. All you need to do is add an override for this method. The reason you need to do this is because you have changed the way equality works, so without a custom hashcode, you can end up with two different objects with the same hashcode - hence a problem with equality. BTW, you should have posted this in the C# forum as it's a generic C# problem. The fact that the application is WPF is neither here nor there.I'm not a stalker, I just know things. Oh by the way, you're out of milk.
Forgive your enemies - it messes with their heads
-
Hello Everyone I have created a Client/Server application on C# on WPF IDE and I have a little problem on my UserClient property class... Within this class I have a method called:
public override bool Equals(object obj)
{
UserClient temp = obj as UserClient;
if (temp != null)
{
return (userId == temp.userId);
}
if (temp != null)
{
return (userPass == temp.userPass);
}
return false;
}The problem I'm having is: The class UserClient is highlighted with a green line under-neath where when I place MouseOver it sas: UserClient overrides Object.Equals but does not override Object.GetHashCode Here is the entire UserClient class code:
using System;
using System.Collections;
using System.Collections.Generic;
using System.Data;
using System.Diagnostics;namespace DtposClient
{
public class UserClient
{
// User Client Global variables
// ====================================
private string UserFullName;
private string UserAccessLevel;
private int UserId;
private int UserPassword;public string fullName { get { return UserFullName; } set { UserFullName = value; } } public string accLevel { get { return UserAccessLevel; } set { UserAccessLevel = value; } } public int userId { get { return UserId; } set { UserId = value; } } public int userPass { get { return UserPassword; } set { UserPassword = value; } } public override bool Equals(object obj) { UserClient temp = obj as UserClient; if (temp != null) { return (userId == temp.userId); } if (temp != null) { return (userPass == temp.userPass); } return false; } public UserClient(string fullNam, string aLevel, int usId, int pass) { fullName = fullNam; accLevel = aLevel; userId = usId; userPass = pass; } }
}
Could someone please help me crack this problem.... thanks in advance kind regards lapeci
You can always use the
new
method to create a method of your own (breaking away from the inheritance hierarchy).The funniest thing about this particular signature is that by the time you realise it doesn't say anything it's too late to stop reading it. My latest tip/trick