Wrox Programmer Forums
|
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 7th, 2012, 09:01 AM
Authorized User
 
Join Date: Sep 2012
Posts: 29
Thanks: 14
Thanked 0 Times in 0 Posts
Default outputting iterations

// class Class1{
void Main()
{
int i = 1;
for (int a =0; a<11 ; a++)
Console.WriteLine(i++);
itr itrobj=new itr();

Console.WriteLine(itrobj.meth());
}
}
// Define other methods and classes here

class itr
{ int j = 1;
public int meth()
{
for(int b = 0 ; b<5 ; b++)
Console.WriteLine(j++);
return ??????;

}
}


I want to get this o/p
1
2
3
.
.
.
11
1
2
.
.
5

PLS Note that I would not like to tamper with the "b<5" part, that might b
e a requirement
any way out
.
 
Old September 7th, 2012, 09:18 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 Class1{
void Main()
{
 int i = 1;
 for (int a =0; a<11 ; a++)
 Console.WriteLine(i++);
 itr itrobj=new itr();
 
 Console.WriteLine(itrobj.meth());
}
} 
// Define other methods and classes here

class itr
{ int j = 1;
public int meth()
{
for(int b = 0 ; b<5 ; b++)
Console.WriteLine(j++);
return ??????;

}
}
I want to get this o/p
1
2
3
.
.
.
11
1
2
.
.
5

PLS Note that I would not like to tamper with the "b<5" part, that might b
e a requirement
any way out
.
Why do you return a value from the method meth? You do the WriteLine inside this method anyway.
From the Main method you can invoke it with itrobj.meth(); without passing it to Console.WriteLine.
__________________
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, 09:20 AM
Authorized User
 
Join Date: Sep 2012
Posts: 29
Thanks: 14
Thanked 0 Times in 0 Posts
Default

great
regards
amigo1





Similar Threads
Thread Thread Starter Forum Replies Last Post
Outputting a Namespace as an attribute Neal XSLT 1 March 4th, 2009 08:28 AM
Not outputting a specific node zach_1988 XSLT 3 December 2nd, 2008 10:49 AM
Outputting values of a selection effection XSLT 7 September 4th, 2008 12:02 PM
Outputting Array manih C++ Programming 2 June 14th, 2006 08:24 PM





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