Solved

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

Posted on 2016-10-12
2
25 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
Comment Utility
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
Comment Utility
thanks!  I know C# is designed to not use pointers.
0

Featured Post

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

Article by: Ivo
Anonymous Types in C# by Ivo Stoykov Anonymous Types are useful when  we do not need to follow usual work-flow -- creating object of some type, assign some read-only values and then doing something with them. Instead we can encapsulate this read…
Article by: Najam
Having new technologies does not mean they will completely replace old components.  Recently I had to create WCF that will be called by VB6 component.  Here I will describe what steps one should follow while doing so, please feel free to post any qu…
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

762 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

Need Help in Real-Time?

Connect with top rated Experts

8 Experts available now in Live!

Get 1:1 Help Now