Wrox Programmer Forums
Go Back   Wrox Programmer Forums > C# and C > C# 4.0 aka C# 2010 > C# 4.0 aka C# 2010 General Discussion
|
C# 4.0 aka C# 2010 General Discussion Discussions about the C# 4.0, C# 4, Visual C# 2010 language and tool not related to any specific Wrox book
Welcome to the p2p.wrox.com Forums.

You are currently viewing the C# 4.0 aka C# 2010 General Discussion section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old September 6th, 2012, 03:26 AM
Authorized User
 
Join Date: Sep 2012
Posts: 29
Thanks: 14
Thanked 0 Times in 0 Posts
Default concepts of looping inside methods unclear

class mainclass{
void Main()
{


int ii =1; // perfectly working
for (int a =0 ; a<11 ; a++) // perfectly working
Console.WriteLine(ii++); // perfectly working

}
}

class itr
{
int i =1;
public int meth(){
for (int a =0 ; a<9 ; a++)
Console.WriteLine(i++);
}
}


error :
not all code paths return a value -- why and what this means?
================================================== ============================




class mainclass{
void Main()
{

int ii =1; // perfectly working
for (int a =0 ; a<11 ; a++) // perfectly working
Console.WriteLine(ii++); // perfectly working

}
}

class itr
{

int i =1;
public void meth(){
for (int a =0 ; a<9 ; a++)
Console.WriteLine(i++);
}
}

o/p
the above code does compile to give an output of the previous
loop i.e., for the a<11 part
the lower loop is not taken into account --- why
 
Old September 6th, 2012, 05:28 AM
Wrox Author
 
Join Date: Sep 2010
Posts: 175
Thanks: 3
Thanked 53 Times in 53 Posts
Default

Quote:
Originally Posted by amigo1 View Post
Code:
class mainclass{
void Main()
{
	
	
	int ii =1;                 // perfectly working
 for (int a =0 ;  a<11 ; a++)  // perfectly working
Console.WriteLine(ii++);      // perfectly working  
	
}
}

 class itr 
{
  int i =1; 
  public  int meth(){
   for (int a =0 ;  a<9 ; a++)
  Console.WriteLine(i++);
  }
}
error :
not all code paths return a value -- why and what this means?
================================================== ============================
The method meth is declared to return an int, and it doesn't return anything. Such a method must be declared of type void.

Quote:
Originally Posted by amigo1 View Post
Code:
 class mainclass{
void Main()
{

	int ii =1;                 // perfectly working
 for (int a =0 ;  a<11 ; a++)  // perfectly working
Console.WriteLine(ii++);      // perfectly working  
	
}
}

 class itr 
{

int i =1; 
 public  void meth(){
   for (int a =0 ;  a<9 ; a++)
  Console.WriteLine(i++);
  }
}
o/p
the above code does compile to give an output of the previous
loop i.e., for the a<11 part
the lower loop is not taken into account --- why
The method meth is never invoked. The Main method is the entry point in the application and is invoked. You need to instantiate an object of itr, and invoke the meth method.

Hope this helps.
__________________
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:
amigo1 (September 7th, 2012)
 
Old September 7th, 2012, 02:46 AM
Authorized User
 
Join Date: Sep 2012
Posts: 29
Thanks: 14
Thanked 0 Times in 0 Posts
Default thankyou teacher

Thank you teacher
How are you?
-- another thing --
in many forums I find that there are credit systems , for example a member who answers are either given credits( e.g.SDN)
or thank-you-marks for all the pains they go through to answer queries . I did not find this here -- if there is a link if you may please ,, i mean i may carry on the duties
regards
amigo1
 
Old September 7th, 2012, 07:45 AM
Wrox Author
 
Join Date: Sep 2010
Posts: 175
Thanks: 3
Thanked 53 Times in 53 Posts
Default

Quote:
Originally Posted by amigo1 View Post
-- another thing --
in many forums I find that there are credit systems , for example a member who answers are either given credits( e.g.SDN)
or thank-you-marks for all the pains they go through to answer queries . I did not find this here -- if there is a link if you may please ,, i mean i may carry on the duties
regards
amigo1
You can click the "Thanks" button in the lower right corner of the post that was the answer ;-)
__________________
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:
amigo1 (September 7th, 2012)





Similar Threads
Thread Thread Starter Forum Replies Last Post
Unclear instructions, page 211 Howie S BOOK: Beginning SharePoint Designer 2010 0 March 7th, 2011 11:14 AM
unclear use of generic types raghavshukla Pro Java 1 March 5th, 2009 03:14 AM
Unclear instructions in chapter 1 page 15 Merocal BOOK: Beginning ASP.NET 2.0 BOOK VB ISBN: 978-0-7645-8850-1; C# ISBN: 978-0-470-04258-8 17 January 14th, 2007 06:54 PM
c++ concepts kerby C++ Programming 3 April 16th, 2005 11:39 PM





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