Scope within do{} ?

  • Thread starter Thread starter David Haynes
  • Start date Start date
D

David Haynes

I am having a problem making values inside a do block persist.

I have:
Disk disk = new Disk();
node.Current.MoveToFirstChild();
do {
switch(node.Current.Name) {
case "lun":
disk.lun = node.Current.Value;
break;
case "file_name":
disk.file_name = node.Current.Value;
break;
case "disk_size":
disk.size = node.Current.ValueAsInt;
break;
}
} while( node.Current.MoveToNext() );
disk.units = units;

logger.Debug("disk lun = " + disk.Lun);
logger.Debug("disk file name = " + disk.file_name);
logger.Debug("disk size = " + disk.size);
logger.Debug("disk units = " + disk.units);

None of the disk member values are set.

So far, I know:
1. that each case is being run
2. that when I debug the set{} in disk, the value is empty

It's probably something simple but I'm not seeing it.

Ideas?
-david-
 
I would just set a breakpoint at the top of the loop and watch it set the
values ...

Should be pretty easy to see whats going on (i.e. look at what
node.Current.Value is)
 
if C# implemented closures like javascript, that problem would mostly go
away. Why doesn't C# implement closures?

--
________________________
Warm regards,
Alvin Bruney [MVP ASP.NET]

[Shameless Author plug]
Professional VSTO.NET - Wrox/Wiley
The O.W.C. Black Book with .NET
www.lulu.com/owc, Amazon
Blog: http://www.msmvps.com/blogs/alvin
 
Alvin said:
if C# implemented closures like javascript, that problem would mostly go
away. Why doesn't C# implement closures?

Indeed, having been looking at Groovy for a while, I'd love to see
closures in C#.
Compile-time type safety is the main issue, I suspect - anonymous
methods in C# 2.0 are sort of like closures, but you need to have a
delegate of the right signature to start with...

I've been considering starting a Groovy port to C# - anyone interested?

Jon
 
Thanks to everyone who responded.
With a little debugging and careful reading of the C# reference manual,
I found my mistake.

-david-
 
With the time that I have .. yes very ...

Contact me offline Jon...

gregory_young_1@googleemail and remove underscores
 
Ignacio said:
Hi

Which was?

It was embarrassing.

For some reason, I had the setter as:

public string lun {
get { return m_lun; }
set { m_lun = lun; }
}

where it should have been:

public string lun {
get { return m_lun; }
set { m_lun = value; }
}

My only excuse was that it was late at night...

-david-
 

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

Back
Top