So how well do you think you know C#?
-
Without compiling the following code, what will be the result, if run?
class Program
{
static void Main(string[] args)
{
object r = Foo(true);
Console.WriteLine(r.GetType());
Console.ReadLine();
}static object Foo(bool e)
{
return e ? 0 : 0.0;
}
}Now compile and run the code? Are you surprised? If so, try figure it out, if not, then kudos to you :)
xacc.ide - now with TabsToSpaces support
IronScheme - 1.0 alpha 4a out now (29 May 2008) -
Without compiling the following code, what will be the result, if run?
class Program
{
static void Main(string[] args)
{
object r = Foo(true);
Console.WriteLine(r.GetType());
Console.ReadLine();
}static object Foo(bool e)
{
return e ? 0 : 0.0;
}
}Now compile and run the code? Are you surprised? If so, try figure it out, if not, then kudos to you :)
xacc.ide - now with TabsToSpaces support
IronScheme - 1.0 alpha 4a out now (29 May 2008)Double I would imagine due to this:
return e ? 0 : 0.0;
. The thing with this if-expression, is that the true and false types must be of same or assignable types. In this case an int can be cast into a double, but not vice versa. Because of this, the compiler will promote the 0 to a 0.0, hence double. -
Without compiling the following code, what will be the result, if run?
class Program
{
static void Main(string[] args)
{
object r = Foo(true);
Console.WriteLine(r.GetType());
Console.ReadLine();
}static object Foo(bool e)
{
return e ? 0 : 0.0;
}
}Now compile and run the code? Are you surprised? If so, try figure it out, if not, then kudos to you :)
xacc.ide - now with TabsToSpaces support
IronScheme - 1.0 alpha 4a out now (29 May 2008)It's the same as doing
object x = 2 * 1.0;
Console.WriteLine(x.GetType());which is more obvious.
-
Double I would imagine due to this:
return e ? 0 : 0.0;
. The thing with this if-expression, is that the true and false types must be of same or assignable types. In this case an int can be cast into a double, but not vice versa. Because of this, the compiler will promote the 0 to a 0.0, hence double. -
It's the same as doing
object x = 2 * 1.0;
Console.WriteLine(x.GetType());which is more obvious.
blackjack2150 wrote:
It's the same as doing
Not exactly. In you case, the result becomes a double. In my example, the 0 is converted to a double at compile time.
xacc.ide - now with TabsToSpaces support
IronScheme - 1.0 alpha 4a out now (29 May 2008) -
You people are too smart so early in the morning! ;P
xacc.ide - now with TabsToSpaces support
IronScheme - 1.0 alpha 4a out now (29 May 2008)Smart? Nah, I give experience credit for this. Also, if you think about it, it has to be this way. Numbers aren't that different from objects in OOP. I think this code makes it more apparent:
(boolval ? new Car() : new AirPlane()).Fly();
Since C# is statically typed, method selection can't be left to runtime binding. :) -
Without compiling the following code, what will be the result, if run?
class Program
{
static void Main(string[] args)
{
object r = Foo(true);
Console.WriteLine(r.GetType());
Console.ReadLine();
}static object Foo(bool e)
{
return e ? 0 : 0.0;
}
}Now compile and run the code? Are you surprised? If so, try figure it out, if not, then kudos to you :)
xacc.ide - now with TabsToSpaces support
IronScheme - 1.0 alpha 4a out now (29 May 2008)double, and I'd be surprised if it were anything else...
Don't forget to vote if the response was helpful
Sig history "dad" Ishmail-Samuel Mustafa "You're an idiot." John Simmons, THE Outlaw programmer "I realised that all of my best anecdotes started with "So there we were, pissed". Pete O'Hanlon Unix is a Four Letter Word, and Vi is a Two Letter Abbreviation
-
Smart? Nah, I give experience credit for this. Also, if you think about it, it has to be this way. Numbers aren't that different from objects in OOP. I think this code makes it more apparent:
(boolval ? new Car() : new AirPlane()).Fly();
Since C# is statically typed, method selection can't be left to runtime binding. :) -
double, and I'd be surprised if it were anything else...
Don't forget to vote if the response was helpful
Sig history "dad" Ishmail-Samuel Mustafa "You're an idiot." John Simmons, THE Outlaw programmer "I realised that all of my best anecdotes started with "So there we were, pissed". Pete O'Hanlon Unix is a Four Letter Word, and Vi is a Two Letter Abbreviation
Extremely useful
-
Extremely useful
in what sense? :confused:
Don't forget to vote if the response was helpful
Sig history "dad" Ishmail-Samuel Mustafa "You're an idiot." John Simmons, THE Outlaw programmer "I realised that all of my best anecdotes started with "So there we were, pissed". Pete O'Hanlon Unix is a Four Letter Word, and Vi is a Two Letter Abbreviation
-
in what sense? :confused:
Don't forget to vote if the response was helpful
Sig history "dad" Ishmail-Samuel Mustafa "You're an idiot." John Simmons, THE Outlaw programmer "I realised that all of my best anecdotes started with "So there we were, pissed". Pete O'Hanlon Unix is a Four Letter Word, and Vi is a Two Letter Abbreviation
Your sig... ;)
-
Your sig... ;)
:doh: :laugh:
Don't forget to vote if the response was helpful
Sig history "dad" Ishmail-Samuel Mustafa "You're an idiot." John Simmons, THE Outlaw programmer "I realised that all of my best anecdotes started with "So there we were, pissed". Pete O'Hanlon Unix is a Four Letter Word, and Vi is a Two Letter Abbreviation
-
double, and I'd be surprised if it were anything else...
Don't forget to vote if the response was helpful
Sig history "dad" Ishmail-Samuel Mustafa "You're an idiot." John Simmons, THE Outlaw programmer "I realised that all of my best anecdotes started with "So there we were, pissed". Pete O'Hanlon Unix is a Four Letter Word, and Vi is a Two Letter Abbreviation
Mustafa Ismail Mustafa wrote:
double, and I'd be surprised if it were anything else...
double, and I'd be surprised pissed off if it were anything else... (I'm in the process of learning C#)
Software Zen:
delete this;
-
Without compiling the following code, what will be the result, if run?
class Program
{
static void Main(string[] args)
{
object r = Foo(true);
Console.WriteLine(r.GetType());
Console.ReadLine();
}static object Foo(bool e)
{
return e ? 0 : 0.0;
}
}Now compile and run the code? Are you surprised? If so, try figure it out, if not, then kudos to you :)
xacc.ide - now with TabsToSpaces support
IronScheme - 1.0 alpha 4a out now (29 May 2008)How do you get formatted and colorised code like that? Is there a tool or something? Do you mind sharing it with me? :)
Many are stubborn in pursuit of the path they have chosen, few in pursuit of the goal - Friedrich Nietzsche .·´¯`·->Rajesh<-·´¯`·. [Microsoft MVP - Visual C++]
-
How do you get formatted and colorised code like that? Is there a tool or something? Do you mind sharing it with me? :)
Many are stubborn in pursuit of the path they have chosen, few in pursuit of the goal - Friedrich Nietzsche .·´¯`·->Rajesh<-·´¯`·. [Microsoft MVP - Visual C++]
Rajesh R Subramanian wrote:
How do you get formatted and colorised code like that? Is there a tool or something? Do you mind sharing it with me?
xacc.ide*, select text, right click, copy special, copy to HTML :) * see link below
xacc.ide - now with TabsToSpaces support
IronScheme - 1.0 alpha 4a out now (29 May 2008) -
Rajesh R Subramanian wrote:
How do you get formatted and colorised code like that? Is there a tool or something? Do you mind sharing it with me?
xacc.ide*, select text, right click, copy special, copy to HTML :) * see link below
xacc.ide - now with TabsToSpaces support
IronScheme - 1.0 alpha 4a out now (29 May 2008)It works with C++? Will I be able to specify a background color of my option? I know that I can modify the HTML, but I'm just asking. I'm downloading it at the moment. Thanks.
Many are stubborn in pursuit of the path they have chosen, few in pursuit of the goal - Friedrich Nietzsche .·´¯`·->Rajesh<-·´¯`·. [Microsoft MVP - Visual C++]
-
It works with C++? Will I be able to specify a background color of my option? I know that I can modify the HTML, but I'm just asking. I'm downloading it at the moment. Thanks.
Many are stubborn in pursuit of the path they have chosen, few in pursuit of the goal - Friedrich Nietzsche .·´¯`·->Rajesh<-·´¯`·. [Microsoft MVP - Visual C++]
Rajesh R Subramanian wrote:
It works with C++?
Not as nice as C#, but ok :)
Rajesh R Subramanian wrote:
Will I be able to specify a background color of my option? I know that I can modify the HTML, but I'm just asking.
Nope, not IIRC, it just defaults to white, I cant remember if it picks up the color from the editor, or if that color can even be changed! Been very long since I wrote that :)
xacc.ide - now with TabsToSpaces support
IronScheme - 1.0 alpha 4a out now (29 May 2008) -
Rajesh R Subramanian wrote:
It works with C++?
Not as nice as C#, but ok :)
Rajesh R Subramanian wrote:
Will I be able to specify a background color of my option? I know that I can modify the HTML, but I'm just asking.
Nope, not IIRC, it just defaults to white, I cant remember if it picks up the color from the editor, or if that color can even be changed! Been very long since I wrote that :)
xacc.ide - now with TabsToSpaces support
IronScheme - 1.0 alpha 4a out now (29 May 2008)I might give it a shot to add those features of my choice if time permits. I hardly work with C#. Thanks for the tool anyways.
Many are stubborn in pursuit of the path they have chosen, few in pursuit of the goal - Friedrich Nietzsche .·´¯`·->Rajesh<-·´¯`·. [Microsoft MVP - Visual C++]
-
Without compiling the following code, what will be the result, if run?
class Program
{
static void Main(string[] args)
{
object r = Foo(true);
Console.WriteLine(r.GetType());
Console.ReadLine();
}static object Foo(bool e)
{
return e ? 0 : 0.0;
}
}Now compile and run the code? Are you surprised? If so, try figure it out, if not, then kudos to you :)
xacc.ide - now with TabsToSpaces support
IronScheme - 1.0 alpha 4a out now (29 May 2008)i say double, but one of our new devs, thought it was a bool, then an object, then gave up and had me explain it. person has the same title as me too, funny how i never cared about that stuff until i got one. hopefully the other new guy will do better.
Please remember to rate helpful or unhelpful answers, it lets us and people reading the forums know if our answers are any good.
-
Mustafa Ismail Mustafa wrote:
double, and I'd be surprised if it were anything else...
double, and I'd be surprised pissed off if it were anything else... (I'm in the process of learning C#)
Software Zen:
delete this;
Gary Wheeler wrote:
double, and I'd be surprised pissed off if it were anything else...
I stand corrected :)
Gary Wheeler wrote:
(I'm in the process of learning C#)
From what I remember, you're a C++er. Don't worry, you'll pick it up in no time flat, but you'll hate some stuff. const comes as a[n unpleasant] surprise and so do reflection issues. All in all, its a nice language :)
Don't forget to vote if the response was helpful
Sig history "dad" Ishmail-Samuel Mustafa "You're an idiot." John Simmons, THE Outlaw programmer "I realised that all of my best anecdotes started with "So there we were, pissed". Pete O'Hanlon Unix is a Four Letter Word, and Vi is a Two Letter Abbreviation