Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8649781
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T13:38:44+00:00 2026-06-12T13:38:44+00:00

I am working on win-form app that has . net 2.0 as framework. I

  • 0

I am working on win-form app that has .net 2.0 as framework. I have a list of an class in which i would like to check if the object already exist before adding it in list. I know i can use .Any of linq to do this but it does not work in my situation. I can not use .contains since the object will not be same as it has lot of properties , so I am left with a unique property to check if it is already added,but it is not working Code:

bool alreadyExists = exceptionsList.Exists(item =>
       item.UserDetail == ObjException.UserDetail    
    && item.ExceptionType != ObjException.ExceptionType) ;

My class

public class AddException
    {
        public string  UserDetail{ get; set; }
        public string  Reason { get; set; }
        public Enumerations.ExceptionType ExceptionType { get; set; }

    }
    public class Enumerations
    {
        public enum ExceptionType
        {
            Members = 1,
            Senders =2
        }
    }

Iniial situation

AddException objException = new AddException
                {
                    Reason = "test",
                    UserDetail = "Ankur",
                    ExceptionType = 1
                };

this object is added in list.

Second time

AddException objException = new AddException
                {
                    Reason = "test 1234",
                    UserDetail = "Ankur",
                    ExceptionType = 1
                };

this should not be getting added in the list , but the .Exist check is failing and it is getting added in the list.

Any suggestions.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T13:38:46+00:00Added an answer on June 12, 2026 at 1:38 pm

    Exists returns already the bool and not an object, so your null check at the end doesn’t work.

    bool alreadyExists = exceptionsList.Exists(item =>
            item.UserDetail == ObjException.UserDetail
         && item.ExceptionType == ObjException.ExceptionType
    );
    

    The important part is, you have to change

    item.ExceptionType != ObjException.ExceptionType
    

    to

    item.ExceptionType == ObjException.ExceptionType
    

    since you want to know if there are items which are equal by UserDetail and ExceptionType.

    Also note that you should not initialize Enums with their int-value. So change

    AddException objException = new AddException
    {
        Reason = "test 1234",
        UserDetail = "Ankur",
        ExceptionType = 1
    };
    

    to

    AddException objException = new AddException
    {
        Reason = "test 1234",
        UserDetail = "Ankur",
        ExceptionType = Enumerations.ExceptionType.Members
    };
    

    (By the way, that should not even compile)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm working on a legacy vb.net winform app, and would like to have have
I working on a C# win-form app. in my form i have Data-Grid-View that
We're working on a Windows App that periodically has to launch operations which may
I have an .NET 4 .exe (Winform Desktop app) to which I have added
I am working on vb.net win form. My task is display the file names
I'm working on WinForm app in VS2008, I have a sql table that is
I have been working on a project that has 2 interfaces - windows forms
I am working on a little WinForm app and have been trying to find
I have the following situation: .net 3.5 WinForm client app accessing SQL Server 2008
I'm developing a WinForm app for Windows Mobile 6.0 with C#, .NET Compact Framework

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.