473,378 Members | 1,156 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

Overloading []

Hi.
Iam creating Matrix class and i wanna access members of an object like:
matrixObject[i.j] = anyNumber;

How to overload [] operator?
PK
Nov 17 '05 #1
5 1099
Hi,

Something like:

public class MyMatricObject
{
public object this[int x, int y]
{
get; set; // Fill
}

public object this[string x, string y]
{
get; set; // Fill
}
}

Kr. Soren

"piotrek" <pi*************@gmail.com> skrev i en meddelelse
news:31**************************@news.chello.pl.. .
Hi.
Iam creating Matrix class and i wanna access members of an object like:
matrixObject[i.j] = anyNumber;

How to overload [] operator?
PK

Nov 17 '05 #2
Thank you, but how to set the member then?

When i can access member by []... then i need to set the value.
Now in my code it looks like:

public float this[int x, int y]

{

set

{

M[x, y] = 0;

}

get

{

return M[x, y];

}

}

How to replace 0 in set accesor, by the value after = sign?

PK
Nov 17 '05 #3
Hi,

Use the "value" keyword

public float this[int x, int y]
{
get
{
return M[x,y];
}
set
{
M[x,y] = value;
}
}

Kr. Soren

"piotrek" <pi*************@gmail.com> skrev i en meddelelse
news:85**************************@news.chello.pl.. .
Thank you, but how to set the member then?

When i can access member by []... then i need to set the value.
Now in my code it looks like:

public float this[int x, int y]

{

set

{

M[x, y] = 0;

}

get

{

return M[x, y];

}

}

How to replace 0 in set accesor, by the value after = sign?

PK

Nov 17 '05 #4
"piotrek" <pi*************@gmail.com> a écrit dans le message de news:
85**************************@news.chello.pl...

| How to replace 0 in set accesor, by the value after = sign?

public float this[int x, int y]
{
get
{
return M[x, y];
}
set
{
M[x, y] = value;
}
}

Joanna

--
Joanna Carter [TeamB]
Consultant Software Engineer
Nov 17 '05 #5
Thank all of you...
PK
Nov 17 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

17
by: Terje Slettebø | last post by:
To round off my trilogy of "why"'s about PHP... :) If this subject have been discussed before, I'd appreciate a pointer to it. I again haven't found it in a search of the PHP groups. The PHP...
4
by: Dave Theese | last post by:
Hello all, I'm trying to get a grasp of the difference between specializing a function template and overloading it. The example below has a primary template, a specialization and an overload. ...
5
by: | last post by:
Hi all, I've been using C++ for quite a while now and I've come to the point where I need to overload new and delete inorder to track memory and probably some profiling stuff too. I know that...
39
by: zeus | last post by:
I know function overloading is not supported in C. I have a few questions about this: 1. Why? is it from technical reasons? if so, which? 2. why wasn't it introduced to the ANSI? 3. Is there any...
45
by: JaSeong Ju | last post by:
I would like to overload a C function. Is there any easy way to do this?
31
by: | last post by:
Hi, Why can I not overload on just the return type? Say for example. public int blah(int x) { }
2
by: brzozo2 | last post by:
Hello, this program might look abit long, but it's pretty simple and easy to follow. What it does is read from a file, outputs the contents to screen, and then writes them to a different file. It...
15
by: lordkain | last post by:
is it possible to do some kind of function overloading in c? and that the return type is different
11
by: placid | last post by:
Hi all, Is it possible to be able to do the following in Python? class Test: def __init__(self): pass def puts(self, str): print str
10
by: Matthew | last post by:
Am I correct in thinking there is no method/function overloading of any kind in any version of PHP? Thanks, Matthew
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.