1) What will the value of txt be after executing MyFunction?
public void Main()
{
string txt = MyFunction( “12345” );
}
public string MyFunction( string str )
{
if( str.Length == 1 )
return str;
else
return MyFunction(str.Substring(1, str.Length - 1)) + str.Substring(0,1);
}
Hint:
String.Substring( startIndex, length ) 6 1916
seema,
Have you compiled this and seen what will be output?
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com
"seema" <se***@discussions.microsoft.comwrote in message
news:81**********************************@microsof t.com...
1) What will the value of txt be after executing MyFunction?
public void Main()
{
string txt = MyFunction( "12345" );
}
public string MyFunction( string str )
{
if( str.Length == 1 )
return str;
else
return MyFunction(str.Substring(1, str.Length - 1)) + str.Substring(0,1);
}
Hint:
String.Substring( startIndex, length )
It looks like someone doesn't want to do their own homework... will
eventually become a professional meeting attender (if not burger flipper).
-S
"Nicholas Paldino [.NET/C# MVP]" <mv*@spam.guard.caspershouse.comwrote in
message news:e9**************@TK2MSFTNGP04.phx.gbl...
seema,
Have you compiled this and seen what will be output?
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com
"seema" <se***@discussions.microsoft.comwrote in message
news:81**********************************@microsof t.com...
>1) What will the value of txt be after executing MyFunction?
public void Main() { string txt = MyFunction( "12345" ); }
public string MyFunction( string str ) { if( str.Length == 1 ) return str; else return MyFunction(str.Substring(1, str.Length - 1)) + str.Substring(0,1); } Hint: String.Substring( startIndex, length )
Hi,
Just run it using the debugger
"seema" <se***@discussions.microsoft.comwrote in message
news:81**********************************@microsof t.com...
1) What will the value of txt be after executing MyFunction?
public void Main()
{
string txt = MyFunction( "12345" );
}
public string MyFunction( string str )
{
if( str.Length == 1 )
return str;
else
return MyFunction(str.Substring(1, str.Length - 1)) + str.Substring(0,1);
}
Hint:
String.Substring( startIndex, length )
On Aug 13, 8:54 pm, "Smithers" <A...@B.comwrote:
It looks like someone doesn't want to do their own homework...
Bingo. The typographic quotes are a dead giveaway. =]
seema wrote:
1) What will the value of txt be after executing MyFunction?
public void Main()
{
string txt = MyFunction( “12345” );
}
public string MyFunction( string str )
{
if( str.Length == 1 )
return str;
else
return MyFunction(str.Substring(1, str.Length - 1)) + str.Substring(0,1);
}
Hint:
String.Substring( startIndex, length )
Not really a good hint as that gives no clue as to what will happen.
BTW, this is not the way I would code this, but it appears the goal was
to test the ability to follow a code path through a recursive function
without the aid of a debugger other than your internal debugger (the one
between your ears).
--
Tom Porterfield
My Grandmother used to say that the way to learn about recursion is to study
recursion. She lived to be 100, by the way. It wasn't recursion that killed
her though. I think she had a stack overflow from some Clan McGregor scotch...
--
Recursion: see Recursion
site: http://www.eggheadcafe.com
unBlog: http://petesbloggerama.blogspot.com
BlogMetaFinder: http://www.blogmetafinder.com
"seema" wrote:
1) What will the value of txt be after executing MyFunction?
public void Main()
{
string txt = MyFunction( “12345” );
}
public string MyFunction( string str )
{
if( str.Length == 1 )
return str;
else
return MyFunction(str.Substring(1, str.Length - 1)) + str.Substring(0,1);
}
Hint:
String.Substring( startIndex, length )
This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Glutinous |
last post by:
Trying to learn php, and came across
=&
as in
$form =& $HTTP_POST_VARS;
I can't find any reference to =&, with no success in searching for a
definition (as though it's _so_ obvious it...
|
by: Sims |
last post by:
Hi,
I recall a function that would tell me how long it took to generate an
output.
But for the life of me I cannot remember it.
Dow anybody know it? Or do I have to write something myself,...
|
by: Jeff_Relf |
last post by:
Hi Tom, You showed: <<
private const string PHONE_LIST =
"495.1000__424.1111___(206)564-5555_1.800.325.3333";
static void Main( string args ) {
foreach (string phoneNumber in Regex.Split...
|
by: Neil Zanella |
last post by:
OK, this time the compiler's got me a little bit puzzled, simply because it is
doing something I am not expecting. My understanding, according to the
documentation of std::vector<>::resize(), is...
|
by: yee young han |
last post by:
I need a fast data structure and algorithm like below condition.
(1) this data structure contain only 10,000 data entry.
(2) data structure's one entry is like below
typedef struct _DataEntry_...
| |
by: kalamantina |
last post by:
#include "stdafx.h"
#include <stdio.h>
#define output( x ) printf( #x "\r\n" );fflush( stdout )
class CMyBase
{
public:
CMyBase()
{
output( CMyBase() );
f(*this);
|
by: aboood |
last post by:
Hi guys
Could any one tell me what does that code do please? in pseudo-code
#include <fstream.h>
#include <iostream.h>
bool differsByOneDigit ( int , int );
void outputResults ( ofstream & ,...
|
by: mahesh |
last post by:
Hi all,
I have following code that is supposed to increase the power by
specified value.
int main()
{
system("cls");
int i, exponent;
double base;
double new_base=0.0;
|
by: Philluminati |
last post by:
I have a Perl SOAP Server which returns this SOAP Message when
invoked:
<?xml version="1.0" encoding="UTF-8"?><soap:Envelope xmlns:xsi="http://
www.w3.org/2001/XMLSchema-instance"...
|
by: Yee.Chuang |
last post by:
When I began to learn C, My teacher told me that pointer is the most
difficult part of C, it makes me afraid of it. After finishing C
program class, I found that all the code I wrote in C contains...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
| |
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development projectplanning, coding, testing,...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The...
| |
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
| |