00.Forums
Re: C# Quiz
Started by TanzimSaqib at 11-14-2005 2:14 PM. Topic has 12 replies.
  Page 1 of 1 (13 items)

TanzimSaqib
TanzimSaqib
Added: 2:14 PM on 11/14/2005

Without running the code answer the question.

What will be the output of the following?

 Console.WriteLine( ‘\t’ + ‘\t’ + “Is this double, single or no indented text?” );


---------------
Tanzim Saqib
Web: www.TanzimSaqib.com | Cell: +88.0189.194.193

Dredding
Dredding
Added: 9:29 PM on 11/16/2005

will this actually throw an exception? My first thought is that '\t' is a string escape sequence, but it's noted as though it should be a character (with the single quotes).

ok, i'm going to go run it now hehe



Evangelist
Evangelist
Added: 12:45 AM on 11/17/2005
These won't definately be tabs, since they would have to be in double quotes instead of single quotes. Hmm ... don't know what it'll display, some sort of character representation or something. Good question btw =)

- Microsoft Student Ambassador @ LUMS (Pakistan)

TanzimSaqib
TanzimSaqib
Added: 1:20 PM on 11/17/2005

Hint: Think in terms of Expression Evaluation!

Thanks.

---
Tanzim Saqib
Software Consultant & BSc Student
Cell: 88 0189 194 193


---------------
Tanzim Saqib
Web: www.TanzimSaqib.com | Cell: +88.0189.194.193

razorback
razorback
Added: 6:29 PM on 1/28/2006

With my experience with C# and programming in general, I have found that the single quotes will cause the \t to be interpreted as a character literal, but as with most C# variables, it would have to be converted to the string datatype. In every program I have written, everything has to be explicitly casted so I think that this line of code will give a compile error. If it is not caused by the attempted implicit cast, it will be caused by the fact that two variables of type char cannot be added using the + operator unless the operator was specifically overloaded to allow the two \t to be concatinated into a character array or if the ToString function is called for both \t (this would require more than one line of code). This would cause a WL( char [] + string) that would still need to be implicitly casted and concatinated. Conclusion: compile time error



nendu
nendu
Added: 4:38 AM on 2/24/2006

With out running a program there is no output.

 

So answer is no output.

Any further doubt you first run the code and then find the answer.

 

Thankyou,

Poornendulal.V


nendu

titje
titje
Added: 3:30 AM on 5/15/2006
Nope, it won't give a compiler error, but what actually happens is the following (I think):

Since C# evaluates statements from left to right, the first thing he sees is a char datatype (\t). Next thing he sees is a plus and another char datatype. Now, since the compiler 's got two chars and a plus he casts the two chars to INTEGERS (if you take a look at a good ols ASCII table you'll see a tab is the same as the number 9).

So you get 9 + 9 which equals 18. Only then does the compiler see the next + and a string and only then does the compiler cast the 18 to a string and concatenates this with the rest of the string.

Voila, problem solved. (Next?)

grtz,
titje.


evergreen501
evergreen501
Added: 12:47 AM on 11/10/2006
      Is this double, single or no indented text?

somu_kiran22
somu_kiran22
Added: 7:29 AM on 2/6/2007
18Is this double, single or no indented text?


plismore
plismore
Added: 10:30 AM on 4/19/2007
Does it give indented text

lil snorita
lil snorita
Added: 8:17 PM on 7/24/2007

hello ano po name mo me kenneth thanks