Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

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

Posted on 2016-10-12
2
Medium Priority
?
57 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 20

Accepted Solution

by:
Russ Suter earned 2000 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

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

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

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…
Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …
Suggested Courses

604 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