Click here to Skip to main content
15,910,872 members
Home / Discussions / C#
   

C#

 
GeneralRe: windows application Pin
jashimu9-Jun-10 7:56
jashimu9-Jun-10 7:56 
QuestionLINQ DataContext and IDisposable Pin
Member 39190498-Jun-10 7:01
Member 39190498-Jun-10 7:01 
AnswerRe: LINQ DataContext and IDisposable Pin
Pete O'Hanlon8-Jun-10 10:01
mvePete O'Hanlon8-Jun-10 10:01 
QuestionIndexer Question Pin
David Knechtges8-Jun-10 5:54
David Knechtges8-Jun-10 5:54 
AnswerRe: Indexer Question Pin
harold aptroot8-Jun-10 6:10
harold aptroot8-Jun-10 6:10 
AnswerRe: Indexer Question Pin
T M Gray8-Jun-10 10:45
T M Gray8-Jun-10 10:45 
GeneralRe: Indexer Question Pin
harold aptroot8-Jun-10 10:56
harold aptroot8-Jun-10 10:56 
AnswerRe: Indexer Question Pin
LookSharp8-Jun-10 17:15
LookSharp8-Jun-10 17:15 
You do need a separate class to do what you want to do, and it needs to expose an event that the class that uses it must handle in order to respond to changes in ball states. Here's an example (compiles under VS2008):

namespace BallStateExample 
	{
	enum State {Flashing, Played, NotPlayed}
	delegate void BallStateChanged(BallStateChangedEventArgs e);
	
	class BallStateChangedEventArgs
		{
		public int BallIndex { get; set; }
		public State NewState { get; set; }
		}

		
	class Balls
		{
		private readonly State[] _balls;
		
		public Balls(int numBalls)
			{
			_balls = new State[numBalls];
			}
			
		public event BallStateChanged BallStateChanged;

		private void OnBallStateChanged(int index, State newState)
			{
			if (BallStateChanged != null)
				BallStateChanged(new BallStateChangedEventArgs { BallIndex = index, NewState = newState });
			}
			
		public State this[int index]
			{
			get { return _balls[index]; }
			set
				{
				_balls[index] = value;
				OnBallStateChanged(index, value);
				}
			}
		}
		
		
	class BallUser
		{
		private const int NUM_BALLS = 42;
		
		public BallUser()
			{
			Balls = new Balls(NUM_BALLS);
			Balls.BallStateChanged += Balls_StateChanged;
			}
			
		private void Balls_StateChanged(BallStateChangedEventArgs e)
			{
			// Take action in response to a ball state change
			}

		// ...

		// Auto-property (so no backing store need be declared)
		// Private set accessor to prevent consumers of BallUser from
 		// assigning to the property (an action reserved for the constructor of BallUser).
		public Balls Balls { get; private set; }

		// ...
		}
	}

Questionmaking a text box more efficient Pin
codie30078-Jun-10 5:43
codie30078-Jun-10 5:43 
AnswerRe: making a text box more efficient Pin
Dave Kreskowiak8-Jun-10 6:23
mveDave Kreskowiak8-Jun-10 6:23 
GeneralRe: making a text box more efficient Pin
AspDotNetDev8-Jun-10 9:21
protectorAspDotNetDev8-Jun-10 9:21 
GeneralRe: making a text box more efficient Pin
Dave Kreskowiak8-Jun-10 10:12
mveDave Kreskowiak8-Jun-10 10:12 
GeneralRe: making a text box more efficient Pin
Pete O'Hanlon8-Jun-10 10:42
mvePete O'Hanlon8-Jun-10 10:42 
GeneralRe: making a text box more efficient Pin
Dave Kreskowiak8-Jun-10 12:09
mveDave Kreskowiak8-Jun-10 12:09 
GeneralRe: making a text box more efficient Pin
AspDotNetDev8-Jun-10 10:47
protectorAspDotNetDev8-Jun-10 10:47 
GeneralRe: making a text box more efficient Pin
Luc Pattyn8-Jun-10 11:03
sitebuilderLuc Pattyn8-Jun-10 11:03 
GeneralRe: making a text box more efficient Pin
AspDotNetDev8-Jun-10 12:45
protectorAspDotNetDev8-Jun-10 12:45 
GeneralRe: making a text box more efficient Pin
Luc Pattyn8-Jun-10 12:59
sitebuilderLuc Pattyn8-Jun-10 12:59 
GeneralRe: making a text box more efficient Pin
AspDotNetDev8-Jun-10 13:19
protectorAspDotNetDev8-Jun-10 13:19 
GeneralRe: making a text box more efficient Pin
Luc Pattyn8-Jun-10 13:26
sitebuilderLuc Pattyn8-Jun-10 13:26 
GeneralRe: making a text box more efficient Pin
AspDotNetDev8-Jun-10 13:59
protectorAspDotNetDev8-Jun-10 13:59 
GeneralRe: making a text box more efficient Pin
Luc Pattyn8-Jun-10 14:06
sitebuilderLuc Pattyn8-Jun-10 14:06 
GeneralRe: making a text box more efficient Pin
AspDotNetDev8-Jun-10 14:16
protectorAspDotNetDev8-Jun-10 14:16 
GeneralRe: making a text box more efficient Pin
Luc Pattyn8-Jun-10 14:28
sitebuilderLuc Pattyn8-Jun-10 14:28 
GeneralRe: making a text box more efficient Pin
Dave Kreskowiak8-Jun-10 12:24
mveDave Kreskowiak8-Jun-10 12:24 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.