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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T13:09:51+00:00 2026-05-31T13:09:51+00:00

suppose I have a class like class ABC { int ID; public string Name;

  • 0

suppose I have a class like

class ABC
{
    int ID;
    public string Name;
    public ABC(int i, string str) { ID = i; Name = str; }
}

And declare a array of class ABC.
Assume that I have also initialized each element using new keyword.
Now I want access element of class using it’s member ID instead of 0 based index. Make ID public if required.

public partial class _Default : System.Web.UI.Page 
{
    protected void Page_Load(object sender, EventArgs e)
    {
        ABC[] a = new ABC[3];
        a[0] = new ABC(100, "First");
        a[1] = new ABC(101, "Second");
        a[2] = new ABC(102, "Third");

        ABC newobj = a[100]; // where 100 is ID of class ABC
    }
}

class ABC
{
    int ID;
    string Name;
    public ABC(int i, string str)
    {
         ID = i;
         Name = str;
    }
}
  • 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-31T13:09:52+00:00Added an answer on May 31, 2026 at 1:09 pm

    Overloading the indexer on a standard array isn’t possible in C#. If you have to go the indexer route I’d suggest using Dictionary or a List class that supplies it’s own indexer.

    class ABCCollection : List<ABC>
    {
      public ABC this[int id]
      {
        get { return this.Where(abc => abc.ID == id).FirstOrDefault(); }
      }
    }
    

    Then you call use ABCCollection[100] to access your item.

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

Sidebar

Related Questions

Suppose i have class Person { public int Id {get;set;} public string Name {get;set;}
Suppose I have a class like the following: public class Stage { public int
Suppose I have class like class A{ public: A(int a, boost::shared_ptr<int> ptr){ // whatever!
Suppose I have a simple Java class like this: public class User { String
Suppose I have a class like class A { int x; int y; public:
Suppose I have a C++ class like so: class A { public: A() {
Suppose that I have a Java class with a static method, like so: class
Suppose I have a class like this: public class ThingManager { List<SomeClass> ItemList; public
Suppose I have a class like so: public class StaticDude{ public static Object getGroove()
Suppose we have a class like: Public Class Question Private Shared _field as Integer

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.