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

  • SEARCH
  • Home
  • 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 8266209
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T05:04:27+00:00 2026-06-08T05:04:27+00:00

How to check a list contains a string or any number followed by that

  • 0

How to check a list contains a string or any number followed by that string?
I need to add string in a list. While adding it in the list I have to check whether that string is already exists in that list. If so need to insert that string with integer count.
That is if name is already exists means it should be inserted as “Name1”. If again I am adding Name means it should be inserted as name2. and so on…
How can I achieve this?

List<Names> NameList=new List<Names>();

Name name=new Name();
name.Name="Name";
NameList.Add(Name);

Name name1=new Name();
name1.Name="Name";
NameList.Add(Name1);

Name name2=new Name();
name2.Name="Name";
NameList.Add(Name2);

Public class Name
{
 string Name {get;set; }
}
  • 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-08T05:04:31+00:00Added an answer on June 8, 2026 at 5:04 am

    Your code won’t compile, but I am assuming you are talking about a List<string>. If so, the algorithm could be:

    string val = "Name";
    string toInsert = val;
    int n = 1;
    while(list.Contains(toInsert))
    {
       toInsert = val + n++;
    }
    list.Add(toInsert);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string list and i need to check if any of the
I need to check if my constant contains (string) of any items of my
if I have a list, is there any way to check if it contains
I have a List of string that contains files in which should be ignored
I have a check box list in that user can check or uncheck the
I have a list of check boxes. For the check boxes that are selected,
I have a simple linked list. The node contains a string (value) and an
reader = server.ExecuteReader(CommandType.Text, getPermissionlistQuery, param); var results = new List<string>(); while (reader.Read()) { results.Add(reader[permissionName].ToString());
I have an object that contains a list of other objects. Say it's as
My goal is to check if a string contains any string values from a

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.