TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Peter Price
NA
3
0
Sharing Instantiated Objects in Windows Forms Application - Part II
May 28 2009 12:23 PM
Following is some C# code from a Windows Forms application. As can be seen, a class called Array_Handler is defined along with an event handler called button1_Click. The event handler instantiates an object (newobject) of class Array_Handler, then invokes 2 methods in that class (array_method1 and array_method2).
class Array_Handler
{
private int[][] array1;
private int[][] array2;
// Constructor for class Array_Handler
public Array_Handler()
{
array1 = new int[9][];
// Create 9 columns for each row in array1
for (int i = 0; i < 9; i++)
array1[i] = new int[9];
// Create 9 columns for each row in array2
array2 = new int[9][];
for (int i = 0; i < 9; i++)
array2[i] = new int[9];
}
// Array_Handler Method 1
public int array_method1( int row, int column )
{
return 1;
}
// Array_Handler Method 2
public int array_method2(int row, int column)
{
return 1;
}
} // End class Array_Handler
private void button1_Click(object sender, EventArgs e)
{
int row_index = 0;
int col_index = 0;
int rtrn_value;
Array_Handler newobject = new Array_Handler();
rtrn_value = newobject.array_method1(row_index, col_index);
rtrn_value = newobject.array_method2(row_index, col_index);
}
My question is whether or not another event handler can manipulate the same instantiated object that was just created by button1_Click. Generally, how can multiple event handlers share the same instance of an object?
Thanks,
Peter Price
Reply
Answers (
0
)
Retrieve args value
File System C#