Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. c# Client Server Application

c# Client Server Application

Scheduled Pinned Locked Moved C#
csharphelpvisual-studiowpfsysadmin
4 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • L Offline
    L Offline
    LAPEC
    wrote on last edited by
    #1

    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

    R P _ 3 Replies Last reply
    0
    • L LAPEC

      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

      R Offline
      R Offline
      RobCroll
      wrote on last edited by
      #2

      It's a warning that you are not implementing best practices. You can read the rule description here to understand why

      "You get that on the big jobs."

      1 Reply Last reply
      0
      • L LAPEC

        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

        P Offline
        P Offline
        phil o
        wrote on last edited by
        #3

        Moreover, this code fragment :

        if (temp != null)
        {
        return (userPass == temp.userPass);
        }

        will never be executed (if temp != null, the method will still have returned a value). The error you get is because when you override the Equals() method, compiler is expecting you also override the GetHashCode() one :

        public override int GetHashCode()
        {
        return UserId;
        }

        You can also have a more complex hashcode generation, for example :

        public override int GetHashCode()
        {
        return UserId ^ UserPassword ^ UserFullName.GetHashCode() ^ UserAccessLevel.GetHashCode();
        }

        Here it's up to you to decide which elements of your class will be taken for the hashcode generation.

        1 Reply Last reply
        0
        • L LAPEC

          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

          _ Offline
          _ Offline
          _Erik_
          wrote on last edited by
          #4

          Let me help you with this method:

          public override bool Equals(object obj)
          {
          UserClient temp = obj as UserClient;
          return temp != null && userId == temp.userId && userPass == temp.userPass;
          }

          I guess this is what you wanted it to do. For the warning you mention, I think someone has already told you to make a customized GetHashCode for your UserClient class.

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups