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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T15:33:37+00:00 2026-05-30T15:33:37+00:00

All, I have an application that needs to attach and detach multiple SQL databases

  • 0

All, I have an application that needs to attach and detach multiple SQL databases regularly. I want to create a class that holds all of these databases as a collection that can be iterated over. To do this I am inheriting from ICollection, but there is some thinkg I am not understanding:

class SqlDataBases : ICollection<SqlDb>
{
    private List<SqlDb> dbColl;

    public SqlDataBases()
    {
        dbColl = new List<SqlDb>();
    }

    // Add an index to the collection.
    public SqlDb this[int _nIndex]
    {
        get { return (SqlDb)dbColl[_nIndex]; }
        set { dbColl[_nIndex] = value; }
    }

    // et al.
}

public class DbEnumerator : IEnumerator<SqlDb>
{
    // ...
}

class SqlDb
{
    private string strMdfFullPath;
    private string strLdfFullPath;
    private bool bIsAttached;

    public SqlDb(string _strMdfFullPath, string _strLdfFullPath, bool _bIsAttached)
    {
        this.strMdfFullPath = _strMdfFullPath;
        this.strLdfFullPath = _strLdfFullPath;
        this.bIsAttached = _bIsAttached;
    }
}

My question is “why inherit from ICollection at all, when you have to add methods such as ‘Add’, ‘Contains’ etc. yourself? Or do you have to do this yourself as suggested in MSDN? I have been reading “C# in a Nutshell” and this question is something that stands out unaddressed in this great book.

I apologise, I know I am missing something here…

  • 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-05-30T15:33:39+00:00Added an answer on May 30, 2026 at 3:33 pm

    My question is “why inherit from ICollection at all, when you have to add methods such as ‘Add’, ‘Contains’ etc. yourself?

    ICollection<T> is an interface – it just specifies the members that you have to implement. If you want to derive from something which already has an implementation, look at Collection<T>. You would implement the interface yourself if you wanted to create your own collection data structure with its own special characteristics – I doubt that you want to do that.

    To be honest, it’s not clear why you want your own class here at all – why not just use List<SqlDb> in the client code directly?

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

Sidebar

Related Questions

I have multiple threads (C# application running on IIS) running that all need to
I have a windows form application that uses a Shared class to house all
I have an ASP.NET MVC application that uses Linq to SQL repositories for all
I have an application that (currently) needs to uses DBs served by both SQL
I have this application that will recurse all folders in a given directory and
We have an application that has one or more text console windows that all
I have an application that is going to work like a p2p-software where all
I have an iPad application that pulls in all of its data from an
I have a php application that is installed on several servers and all of
I have a multi-timezone web application that stores all of the datetime values in

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.