Solved

C# pass a button to a method, then treat that button as an array....

Posted on 2016-10-12
2
41 Views
Last Modified: 2016-10-12
I have an array of buttons
        private Button[] Level = new Button[10];

if i pass Level[5] to a method.   How can I, in that method, access Level[4] or Level[6].  In C I can treat it like a pointer and get to any members..

thanks!
0
Comment
Question by:roujesky
2 Comments
 
LVL 20

Accepted Solution

by:
Russ Suter earned 500 total points
ID: 41841031
Short answer, you can't. Single elements of arrays have no knowledge of their container. What you can do is modify your function to accept 2 arguments. The first argument would be the array containing the buttons and the second argument would be the index of the item you wish to focus on.

I have, in the past, added custom collections and subclassed controls so they can reference their containers but that's a bit of effort to implement well for very little return. I'd just go with the 2 argument approach if I were you.
0
 

Author Closing Comment

by:roujesky
ID: 41841035
thanks!  I know C# is designed to not use pointers.
0

Featured Post

Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Extention Methods in C# 3.0 by Ivo Stoykov C# 3.0 offers extension methods. They allow extending existing classes without changing the class's source code or relying on inheritance. These are static methods invoked as instance method. This…
We all know that functional code is the leg that any good program stands on when it comes right down to it, however, if your program lacks a good user interface your product may not have the appeal needed to keep your customers happy. This issue can…
This tutorial gives a high-level tour of the interface of Marketo (a marketing automation tool to help businesses track and engage prospective customers and drive them to purchase). You will see the main areas including Marketing Activities, Design …
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

777 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question