Avatar of g_johnson
g_johnsonFlag for United States of America

asked on 

scope issue C#, VS2008

In the C# code attached, when setting a breakpoint inside the foreach after the ItemNo = blah blah blah statement, in the immediate window I get

?ItemNo
The name 'ItemNo' does not exist in the current context

However, this returns the value I am looking for

?(string)LineItem.Element(sync + "Item").Element(sync + "ItemID").Element(sync + "ID").Value
"HEWC8011A"


What am I doing wrong?  VS2008

var LineItems = from el in ord.Elements(sync + "DataArea")
                 .Elements(sync + "SalesOrder")
                 .Elements(sync + "SalesOrderLine")
                                select el;

                string ItemNo = "";
                string loc = "";
                double qty_ordered = 0;
                double price = 0;

                foreach (var LineItem in LineItems)
                {
                    ItemNo = (string)LineItem.Element(sync + "Item").Element(sync + "ItemID").Element(sync + "ID").Value;

                    OrderHeader.OrdLines.Add(new OrderLine()
                    {
                        item_no = ItemNo,
                        loc = loc,
                        qty_ordered = qty_ordered,
                        price = price,
                        promDate = DateTime.Now.Date,
                        reqDate = DateTime.Now.Date,
                        reqShipDate = DateTime.Now.Date,
                    });

                    ItemNo = "";
                    loc = "";
                    qty_ordered = 0;
                    price = 0;
                }

Open in new window

C#

Avatar of undefined
Last Comment
g_johnson
Avatar of kaufmed
kaufmed
Flag of United States of America image

How and where is ItemNo declared?
Avatar of kaufmed
kaufmed
Flag of United States of America image

Nevermind, I missed it.
ASKER CERTIFIED SOLUTION
Avatar of Todd Gerbert
Todd Gerbert
Flag of United States of America image

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
SOLUTION
Avatar of Pacman
Pacman
Flag of Germany image

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
Avatar of g_johnson
g_johnson
Flag of United States of America image

ASKER

I came in today, changed it to ItemNumber and it worked.  But the variable ItemNo does not appear anywhere in my class except here.  So, out of curiosity, I changed it back and it worked still (as ItemNo).  Very strange!  Thanks for the help
C#
C#

C# is an object-oriented programming language created in conjunction with Microsoft’s .NET framework. Compilation is usually done into the Microsoft Intermediate Language (MSIL), which is then JIT-compiled to native code (and cached) during execution in the Common Language Runtime (CLR).

98K
Questions
--
Followers
--
Top Experts
Get a personalized solution from industry experts
Ask the experts
Read over 600 more reviews

TRUSTED BY

IBM logoIntel logoMicrosoft logoUbisoft logoSAP logo
Qualcomm logoCitrix Systems logoWorkday logoErnst & Young logo
High performer badgeUsers love us badge
LinkedIn logoFacebook logoX logoInstagram logoTikTok logoYouTube logo