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 8357933
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T10:38:36+00:00 2026-06-09T10:38:36+00:00

The short and simple version is this: I have a database. I have a

  • 0

The short and simple version is this: I have a database. I have a c# list that I use to interact with that database. Program starts, dump the data into the list, program ends, save it back into the database.

Here’s my problem though: I need to make sure that one of my attributes in the list (id) is always unique when I create and remove list items. I was thinking maybe a list might have something similiar to a SQL auto-increment? Or perhaps just a numerical index of which item is in which location?

AddedDependents.Add(new Dependent
                   {
                       IsSpouse = isSpouse,
                       Id = /*unique id/*
                   });
  • 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-09T10:38:38+00:00Added an answer on June 9, 2026 at 10:38 am

    You could just use the index of the list:

    AddedDependents.Add(new Dependent
                   {
                       IsSpouse = isSpouse,
                       Id = AddedDependents.Count
                   });
    

    Then the Dependent Id and list index are the same so it becomes trivial to get that Dependent from the list.

    As mentioned in the comments, if you are likely to delete elements from this list then you can’t just get the dependent via the Id, like AddedDependents[dependent.Id] but instead would need to iterate through the list:

    AddedDependents.Where(d => d.Id == dependent.Id);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

We have a simple console app that uses EF 4 to process data; read
Short version: I need mysql code that will change [href=http://a-random-domain.com]hyperlink[/href] into <a href=http://a-random-domain.com>hyperlink</a> without
I have a program that sorts big files by splitting them into chunks, sort
Can someone please break down what a delegate is into a simple, short and
Background: I have a short list of strings. The number of strings is not
Short Version: Does anyone know how to do a simple date insert using Doctrine2?
I have (what I think) is a simple script to send a short mail:
Short version: Is there a simple, built-in way to identify the calling view in
I have approx. 60000 rows with street address in my db that contain short
Short version: assuming I don't want to keep the data for long, how do

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.