{"id":20873708,"url":"https://github.com/zyn10/indexers_csharp_practice","last_synced_at":"2026-05-21T11:07:26.624Z","repository":{"id":149942325,"uuid":"560139450","full_name":"zyn10/Indexers_Csharp_Practice","owner":"zyn10","description":"Indexers practice in csharp","archived":false,"fork":false,"pushed_at":"2022-11-06T19:54:36.000Z","size":8,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-12-29T06:29:50.676Z","etag":null,"topics":["csharp","indexers","lists","objects"],"latest_commit_sha":null,"homepage":"","language":"C#","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/zyn10.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null}},"created_at":"2022-10-31T20:22:59.000Z","updated_at":"2022-11-06T19:53:55.000Z","dependencies_parsed_at":null,"dependency_job_id":"86a34166-c728-4ff4-b485-e004c93f333a","html_url":"https://github.com/zyn10/Indexers_Csharp_Practice","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/zyn10/Indexers_Csharp_Practice","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zyn10%2FIndexers_Csharp_Practice","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zyn10%2FIndexers_Csharp_Practice/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zyn10%2FIndexers_Csharp_Practice/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zyn10%2FIndexers_Csharp_Practice/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/zyn10","download_url":"https://codeload.github.com/zyn10/Indexers_Csharp_Practice/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zyn10%2FIndexers_Csharp_Practice/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":33298344,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-21T02:57:32.698Z","status":"ssl_error","status_checked_at":"2026-05-21T02:57:31.990Z","response_time":62,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["csharp","indexers","lists","objects"],"created_at":"2024-11-18T06:26:51.758Z","updated_at":"2026-05-21T11:07:26.590Z","avatar_url":"https://github.com/zyn10.png","language":"C#","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Indexers in C#\n\nAn indexer allows an object to be indexed such as an array.\n\nWhen you define an indexer for a class, this class behaves similar to a\nvirtual array.\n\nYou can then access the instance of this class using the array access\noperator ([ ]).\n\n\nIn order to understand the scenario lets create a Person class.\n\nGive some attributes like Id and name to it.\n\nclass Person\n\n{\n\npublic int EmpId { get; set; }\n\npublic string EmpName { get; set; }\n\n}\n\nNow let's create a class Company.\n\nWe are already aware of the list class, lets create a Person type list.\n\nAfter that set some initial values of Id and name using constructor.\n\nIn this way we have a “Person” as a data type in the list that we are\ngoing to create.\n\nclass Company\n\n{\n\nprivate List\u003cPerson\u003e listPersons = new List\u003cPerson\u003e();\n\npublic Company()\n\n{\n\nlistPersons.Add(new Person { EmpId = 1, EmpName = \"Awias\" }) ;\n\nlistPersons.Add(new Person { EmpId = 2, EmpName = \"Ali\" });\n\nlistPersons.Add(new Person { EmpId = 3, EmpName = \"Ahmad\" });\n\n}\n\n}\n\nCreate Indexer\n\nNow we have almost all the ingredients to create an indexer that can\nbe useful in our example.\n\nIndexers have a return type, they have parameters and get/set\naccessors.\n\nNow I am going to create a string type indexer with parameter\n“EmpId”.\n\npublic string this[int empId]\n\nAfter that we have to define get and set accessors.\n\nIn get accessor traverse the listPersons and find the id that matches\nwith the parameter passed.\n\nAfter that return the name against that Id.\n\nget\n\n{\n\nforeach(var per in listPersons)\n\n{\n\nif(per.EmpId == empId)\n\n{\n\nreturn per.EmpName;\n\n}\n\n}\n\nreturn null;\n\n}\n\nIn set accessor we can find the object which has the id same as the\npassed parameter and change its name.\n\nset\n\n{\n\nforeach (var per in listPersons)\n\n{\n\nif (per.EmpId == empId)\n\n{\n\nper.EmpName = value;\n\n}\n\n}\n\n}\n\nOverloaded Indexer\n\nWe can have multiple indexers in a class, but they must have differrnt\nparameters.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzyn10%2Findexers_csharp_practice","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fzyn10%2Findexers_csharp_practice","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzyn10%2Findexers_csharp_practice/lists"}