command window / immed window

J

juzan

hi
i have this piece of code but it never shows the ex.tostring in the command
or immed window.
how do i see it?

this is in a class

public void getTeachers()
{
try
{
PermTeacher p =new PermTeacher ();
p.name = "teacher1";
arrTeachers.Add (p);
if (arrTeachers !=null)
Console.WriteLine(this.arrTeachers.Count); //how can i see this?
}
catch(Exception ex)
{
Console.WriteLine(ex.ToString());
}
}
 
G

Gawel

public void getTeachers()
{
try
{
PermTeacher p =new PermTeacher ();
p.name = "teacher1";
arrTeachers.Add (p);
if (arrTeachers !=null)
Console.WriteLine(this.arrTeachers.Count); //how can i see this?
}
catch(Exception ex)
{
Console.WriteLine(ex.ToString());
}
}

That's strange, did you figure out what is going on ?

Gawel
 
P

phoenix

Not 100% sure if I understand you. But isn't Console.... supposed to write
out to the console? Try Debug.WriteLine (Diagnostics namespace) to write to
the other windows

Yves
 
G

Gary Milton

Hi Juzan,

The console output is directed to the 'Output' window (CTRL+ALT+A) in the
IDE and not the command or immediate windows.

Gary
 
G

Gawel

Not 100% sure if I understand you. But isn't Console.... supposed to write
out to the console?

I am using Console.WriteLine all the time and I have no problem.

Gawel
 
K

Kozynenko Ganna

Clever answers do not seem to work, let's try the primitive ones. It's some
second week I am learning C#, so correct me, if I am wrong.

1) Is "this.arrTeachers.Count" actually a string? I bet, it is not.
Then it needs formatting like
Console.WriteLine("{0}",this.arrTeachers.Count);

2) As for ex.ToString, it is not going to be shown unless you introduce some
problem into "try" block. I bet you know that, don't you?

==============
BTW when I try to understand the logic of your checking that arrTeachers is
not null , I feel dizzy :)

Suppose, arrTeachers really happens to be null. Then, the exception is
thrown at the point, where you tried to do the addition ("arrTeachers.Add
(p);"), because u cannot insert something into nothing ;-)

So, if arrTeachers is null, you NEVER reach the "if" statement to see if
arrTeachers is null.

So you check if arrTeachers is not null only in the case when arrTeachers is
definitely not null... %)




Hello, juzan!
You wrote on Sun, 4 Apr 2004 13:17:58 +1000:

j> hi i have this piece of code but it never shows the ex.tostring in
j> the command or immed window.
j> how do i see it?

j> this is in a class

j> public void getTeachers()
j> {
j> try {
j> PermTeacher p =new PermTeacher ();
j> p.name = "teacher1";
j> arrTeachers.Add (p);
j> if (arrTeachers !=null)
j> Console.WriteLine(this.arrTeachers.Count); //how can i see this?
j> }
j> catch(Exception ex)
j> {
j> Console.WriteLine(ex.ToString());
j> }
j> }


With best regards, Kozynenko Ganna. E-mail: (e-mail address removed)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top