Questions tagged [indexer]
367 questions
6
votes
4 answers
C# Indexer properties - Any way to virtualize the get and not the set method?
I have a special type of dictionary. I'm not sure how to do this exactly, but I'm looking to make the get method virtual, but not the set method:
public TValue this[TKey key]
{
get { ... }
set { ... }
}
Is it possible…

myermian
- 31,823
- 24
- 123
- 215
6
votes
1 answer
C# Indexers with Ref Return Gets that also Support Sets
Am I doing something wrong here, or as of C# 7.2 Indexers that return by ref and allow set are not supported?
Works:
public ref byte this[int index] {
get {
return ref bytes[index];
}
}
Works too:
public byte this[int index] {
get {
…

Fit Dev
- 3,413
- 3
- 30
- 54
6
votes
1 answer
List/Collection of references to Properties
Consider these properties,
double _temperature;
public double Temperature
{
get { return _temperature; }
set { _temperature = value; }
}
double _humidity;
public double…

Nawaz
- 353,942
- 115
- 666
- 851
6
votes
2 answers
Why does Eclipse CDT index a header file that's not in the path?
I am using Eclipse CDT v4.3.2 from the ARM DS-5 v5.20.0 package for code development and debug of a Makefile project.
The makefile is actually a hierarchy of mkefiles that create multiple targets in multiple configurations, based on command line…

ysap
- 7,723
- 7
- 59
- 122
6
votes
2 answers
How to use indexers with Extension Methods having out parameter and function calls
Is it possible to use indexers with extension methods.
eg. Consider it as an example only.
public static object SelectedValue(this DataGridView dgv, string ColumnName)
{
return…

Shantanu Gupta
- 20,688
- 54
- 182
- 286
6
votes
2 answers
Indexer constraint on generic types
Is it possible to create a generic class/method where the type must have an indexer?
My thought was to make the following two extension methods work on any type which uses an indexer for getting and setting values, but can't seem to find anything…

Svish
- 152,914
- 173
- 462
- 620
6
votes
2 answers
Eclipse indexer runs every time I start my program
The Eclipse indexer runs from the beginning every time I start my C++ program. Indexing this large program takes 10 minutes so it would help productivity if it could reuse the index it generated before.
This is Eclipse Kepler (4.3.1) SR1 Build id:…

Howard Rubin
- 350
- 2
- 14
6
votes
4 answers
Why does this code have new in the collections indexer
Possible Duplicate:
“new” keyword in property declaration
Pardon me if this is C# 101, but I am trying to understand the code below:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using…

Irfarino
- 522
- 1
- 8
- 13
5
votes
3 answers
Overloaded indexer with enum : impossible to use default indexer
Considering the following code:
namespace MyApp
{
using System;
using System.Collections.ObjectModel;
class Program
{
static void Main(string[] args)
{
var col = new MyCollection();
…

tbolon
- 618
- 9
- 17
5
votes
3 answers
C++/CLI: Implementing IList and IList (explicit implementation of a default indexer)
I am trying to implement a C++/CLI class that implements both IList and IList.
Since they have overlapping names, I have to implement one of them explicitly, and the natural choice should be IList.
The implicit implementation of the indexer…

Rasmus Faber
- 48,631
- 24
- 141
- 189
5
votes
4 answers
What do I do when the Eclipse CDT indexer gets stuck?
I'm using Eclipse CDT 2020-06 (but this has happened to me with earlier versions.)
Sometimes, the Eclipse CDT gets stuck parsing some file. The percentage indicator doesn't advance; and pressing the task's cancel button makes it "Cancel Requested",…

einpoklum
- 118,144
- 57
- 340
- 684
5
votes
1 answer
Ruby indexer method
Is there in Ruby the concept of indexer method such as in C#?

mgamer
- 13,580
- 25
- 87
- 145
5
votes
1 answer
Array indexer signature returns object - does it box?
I stumbled on the fact that the indexer this[int index] { get; } works differently for an array of structs than it does for a List of structs. Namely, that the indexer in the case of an T[] returns a reference to the element within the array whereas…

bright
- 4,700
- 1
- 34
- 59
5
votes
1 answer
TypeScript indexer still getting tslint error "object access via string literals is disallowed"
I am trying to write type definitions for the xmldoc npm package.
So far I have this:
declare module 'xmldoc' {
export class XmlDocument {
constructor(contents: string);
public children: IXmlNode[];
}
export interface IXmlNode {
…

Andrew Murphy
- 53
- 4
5
votes
1 answer
Practical usage of params indexer
Recently, I have found out that indexer can accept an array of arguments as params:
public class SuperDictionary
{
public Dictionary Dict { get; } = new Dictionary();
public IEnumerable…

Yeldar Kurmangaliyev
- 33,467
- 12
- 59
- 101