Click here to Skip to main content
15,906,574 members
Home / Discussions / C#
   

C#

 
AnswerRe: FileSystemWatcher how to wait for file copy completion? Pin
Thomas Krojer7-Feb-11 4:09
Thomas Krojer7-Feb-11 4:09 
AnswerRe: FileSystemWatcher how to wait for file copy completion? Pin
Chesnokov Yuriy7-Feb-11 7:18
professionalChesnokov Yuriy7-Feb-11 7:18 
AnswerRe: FileSystemWatcher how to wait for file copy completion? Pin
#realJSOP7-Feb-11 4:24
professional#realJSOP7-Feb-11 4:24 
AnswerRe: FileSystemWatcher how to wait for file copy completion? Pin
Ennis Ray Lynch, Jr.7-Feb-11 4:26
Ennis Ray Lynch, Jr.7-Feb-11 4:26 
AnswerRe: FileSystemWatcher how to wait for file copy completion? Pin
Luc Pattyn7-Feb-11 4:30
sitebuilderLuc Pattyn7-Feb-11 4:30 
AnswerRe: FileSystemWatcher how to wait for file copy completion? Pin
Pete O'Hanlon7-Feb-11 5:17
mvePete O'Hanlon7-Feb-11 5:17 
AnswerRe: FileSystemWatcher how to wait for file copy completion? Pin
Dave Kreskowiak7-Feb-11 6:28
mveDave Kreskowiak7-Feb-11 6:28 
QuestionProblem by using an Object and a variable inside another function [modified] Pin
nstk7-Feb-11 2:59
nstk7-Feb-11 2:59 
Hello,

trying to build a Windows programm, I 've declared an object in Fornm1.cs by typing
Person[] P = new Person[10];

after a class Person I 've created on another file called Person.cs

Then on the function that is being activated after clicking on a button inside the Form I pass simple numerical values to a member attribute like below:
private void btnObjectAdd_Click(object sender, EventArgs e)
{
    lbltest_i.Text = i.ToString();
    P[i] = new Person();
    P[i].category = i;
    i++;
    if (i == 10)
    {
        for (i = 0; i < 10; i++)
            P[i] = null;
            i = 0;
    }
 }

Thus I get P[0]=0, P[1]=1, ... P[9]=9.

Then I try to call a value of an object on another function like
    private void showToolStripMenuItem_Click(object sender, EventArgs e)
{
   int value = P[2].category;
}

and I get value = 2.

This works perfect.

But if I change
int value = P[2].category;

into
int value = P[i].category;

then I get an error that I should create an object with 'new'.

Variable i is declared as
int i = 0;

outside the functions but inside the
public partial class Form1 : Form

Is that the problem?

modified on Monday, February 7, 2011 1:14 PM

GeneralRe: Problem by using an Object and a variable inside another function Pin
musefan7-Feb-11 3:15
musefan7-Feb-11 3:15 
GeneralRe: Problem by using an Object and a variable inside another function Pin
nstk7-Feb-11 7:19
nstk7-Feb-11 7:19 
Questiondynamic way to analyse settings Pin
arkiboys7-Feb-11 2:55
arkiboys7-Feb-11 2:55 
AnswerRe: dynamic way to analyse settings Pin
musefan7-Feb-11 3:08
musefan7-Feb-11 3:08 
AnswerRe: dynamic way to analyse settings Pin
#realJSOP7-Feb-11 3:42
professional#realJSOP7-Feb-11 3:42 
Questionmessenger Pin
om_metab7-Feb-11 1:19
om_metab7-Feb-11 1:19 
AnswerRe: messenger Pin
OriginalGriff7-Feb-11 1:28
mveOriginalGriff7-Feb-11 1:28 
GeneralRe: messenger Pin
om_metab7-Feb-11 1:43
om_metab7-Feb-11 1:43 
AnswerRe: messenger Pin
Keith Barrow7-Feb-11 1:42
professionalKeith Barrow7-Feb-11 1:42 
GeneralRe: messenger Pin
Abhinav S7-Feb-11 2:27
Abhinav S7-Feb-11 2:27 
GeneralRe: messenger Pin
Keith Barrow7-Feb-11 4:26
professionalKeith Barrow7-Feb-11 4:26 
GeneralRe: messenger Pin
Bernhard Hiller8-Feb-11 3:07
Bernhard Hiller8-Feb-11 3:07 
GeneralRe: messenger Pin
Keith Barrow8-Feb-11 9:41
professionalKeith Barrow8-Feb-11 9:41 
AnswerRe: messenger Pin
PIEBALDconsult7-Feb-11 1:45
mvePIEBALDconsult7-Feb-11 1:45 
GeneralRe: messenger Pin
om_metab7-Feb-11 2:18
om_metab7-Feb-11 2:18 
GeneralRe: messenger PinPopular
Pete O'Hanlon7-Feb-11 2:37
mvePete O'Hanlon7-Feb-11 2:37 
GeneralRe: messenger Pin
Wes Aday7-Feb-11 4:13
professionalWes Aday7-Feb-11 4:13 

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.