Wrox Programmer Forums

Need to download code?

View our list of code downloads.

| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
BOOK: Beginning Visual C# 2010
This is the forum to discuss the Wrox book Beginning Visual C# 2010 by Karli Watson, Christian Nagel, Jacob Hammer Pedersen, Jon D. Reid, Morgan Skinner, ; ISBN: 9780470502266
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Beginning Visual C# 2010 section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
 
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old January 3rd, 2012, 03:55 PM
Authorized User
Points: 98, Level: 1
Points: 98, Level: 1 Points: 98, Level: 1 Points: 98, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Dec 2011
Posts: 23
Thanks: 3
Thanked 0 Times in 0 Posts
Default Chapter 6 Page 140

Intellisense tells me that the int i; outside the loop should not be there:

Quote:
Error 1 A local variable named 'i' cannot be declared in this scope because it would give a different meaning to 'i', which is already used in a 'parent or current' scope to denote something else C:\BegVCSharp\Chapter6\CH06Ex01\page140\Program.cs 14 22 page140
Is the int i; a typo?
  #2 (permalink)  
Old January 4th, 2012, 10:05 AM
Imar's Avatar
Wrox Author
Points: 72,073, Level: 100
Points: 72,073, Level: 100 Points: 72,073, Level: 100 Points: 72,073, Level: 100
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 17,089
Thanks: 80
Thanked 1,587 Times in 1,563 Posts
Default

Hi there,

Can you post your code (I don't have the book). And is this your own code, or code directly taken from the book?

Imar
__________________
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Follow me on Twitter

Author of Beginning ASP.NET 4.5 : in C# and VB, Beginning ASP.NET Web Pages with WebMatrix
and Beginning ASP.NET 4 : in C# and VB.
Did this post help you? Click the button below this post to show your appreciation!
  #3 (permalink)  
Old January 4th, 2012, 10:29 AM
Authorized User
Points: 98, Level: 1
Points: 98, Level: 1 Points: 98, Level: 1 Points: 98, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Dec 2011
Posts: 23
Thanks: 3
Thanked 0 Times in 0 Posts
Default

Quote:
Originally Posted by Imar View Post
Hi there,

Can you post your code (I don't have the book). And is this your own code, or code directly taken from the book?

Imar
Straight out of the book.

int i;
for (i=0, i<10....

Last edited by Frodo; January 4th, 2012 at 10:33 AM..
  #4 (permalink)  
Old January 4th, 2012, 12:07 PM
Imar's Avatar
Wrox Author
Points: 72,073, Level: 100
Points: 72,073, Level: 100 Points: 72,073, Level: 100 Points: 72,073, Level: 100
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 17,089
Thanks: 80
Thanked 1,587 Times in 1,563 Posts
Default

As I said, i don't have the book so I can't check how it's supposed to look.

What you just posted should compile fine, so maybe somewhere else you already defined another i variable? Can you post the full code for the class that contains this loop?

Cheers,

Imar
__________________
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Follow me on Twitter

Author of Beginning ASP.NET 4.5 : in C# and VB, Beginning ASP.NET Web Pages with WebMatrix
and Beginning ASP.NET 4 : in C# and VB.
Did this post help you? Click the button below this post to show your appreciation!
  #5 (permalink)  
Old January 4th, 2012, 08:05 PM
Authorized User
Points: 98, Level: 1
Points: 98, Level: 1 Points: 98, Level: 1 Points: 98, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Dec 2011
Posts: 23
Thanks: 3
Thanked 0 Times in 0 Posts
Default

Code:
int i;
string text = "";
for(i=0;i<10,i++)
{
text="Line "+Convert.ToString(i);
Console.WriteLine("{0}",text);
}
Console.WriteLine("Last text output in loop:{0}",text);
This is on page 141 of the book. Isn't i being defined twice?
  #6 (permalink)  
Old January 4th, 2012, 08:21 PM
Wrox Author
Points: 1,163, Level: 13
Points: 1,163, Level: 13 Points: 1,163, Level: 13 Points: 1,163, Level: 13
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Sep 2010
Location: Austria
Posts: 175
Thanks: 3
Thanked 53 Times in 53 Posts
Default

Quote:
Originally Posted by Frodo View Post
Code:
int i;
string text = "";
for(i=0;i<10,i++)
{
text="Line "+Convert.ToString(i);
Console.WriteLine("{0}",text);
}
Console.WriteLine("Last text output in loop:{0}",text);
This is on page 141 of the book. Isn't i being defined twice?
The code you've posted compiles fine with me if you change the "," in the for statment to ";" as it is in the book. The variable i is declared only once. Probably your code that doesn't compile uses something like this:
Code:
int i;
for (int i = 0; i < 10; i++)
which would create an error you described in the first post as here the variable i is declared a second time within the for statement.
__________________
Christian
CN innovation
Visit my blog at: csharp.christiannagel.com
Follow me on twitter: @christiannagel
The Following User Says Thank You to ChristianNagel For This Useful Post:
Frodo (January 9th, 2012)
  #7 (permalink)  
Old January 9th, 2012, 10:46 AM
Authorized User
Points: 98, Level: 1
Points: 98, Level: 1 Points: 98, Level: 1 Points: 98, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Dec 2011
Posts: 23
Thanks: 3
Thanked 0 Times in 0 Posts
Default

Sorry it's taken me this long to get back to you. Thank you for your responses. I checked my code: I did have a semicolon where you identified the comma in the code that I thought I copied here. I apologize for the typo. This is what I now copy from my file and I get the error I cited below:

Quote:
namespace page140
{
class Program
{
static void Main(string[] args)
{
int i;
string text="";
for (int i = 0; i < 10; i++)
{
text = "Line " + Convert.ToString(i);
Console.WriteLine("{0}",text);
}
Console.WriteLine("Last text output in loop: {0}", text);
}
}
}
  #8 (permalink)  
Old January 9th, 2012, 10:58 AM
Imar's Avatar
Wrox Author
Points: 72,073, Level: 100
Points: 72,073, Level: 100 Points: 72,073, Level: 100 Points: 72,073, Level: 100
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 17,089
Thanks: 80
Thanked 1,587 Times in 1,563 Posts
Default

As suggested earlier, you define i in the loop as well using int.

This:

for (int i = 0; i < 10; i++)

should be

for (i = 0; i < 10; i++)

Alternatively, don't declare i outside the loop.

Hope this helps,

Imar
__________________
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Follow me on Twitter

Author of Beginning ASP.NET 4.5 : in C# and VB, Beginning ASP.NET Web Pages with WebMatrix
and Beginning ASP.NET 4 : in C# and VB.
Did this post help you? Click the button below this post to show your appreciation!
The Following User Says Thank You to Imar For This Useful Post:
Frodo (January 9th, 2012)
  #9 (permalink)  
Old January 9th, 2012, 11:03 AM
Authorized User
Points: 98, Level: 1
Points: 98, Level: 1 Points: 98, Level: 1 Points: 98, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Dec 2011
Posts: 23
Thanks: 3
Thanked 0 Times in 0 Posts
Default

Quote:
Originally Posted by Imar View Post
As suggested earlier, you define i in the loop as well using int.

This:

for (int i = 0; i < 10; i++)

should be

for (i = 0; i < 10; i++)

Alternatively, don't declare i outside the loop.

Hope this helps,

Imar
That's it. Thanks.
 


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
EDMFunction on Page 140 Cza102282 BOOK: Professional ASP.NET MVC 2 22 May 6th, 2011 04:41 PM
chapter 2 - page 41 problem creating the page.. jorjiana BOOK: Beginning Oracle Application Express ISBN: 9780470388372 2 August 22nd, 2009 04:25 AM
Problem with Chapter 2 First Page xtiano77 ASP.NET 3.5 Basics 1 May 7th, 2008 01:00 AM
Stuck At Page 140 Yap Dreamweaver (all versions) 2 October 12th, 2004 06:49 PM



All times are GMT -4. The time now is 06:24 AM.


Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.