![]() |
| | #1 |
| Code Goddess Join Date: Sep 2001
Posts: 9,664
| mmmm C# Here are two quickie programs that show size differences between C# and my beloved C. Code: // C# code
using System;
class Print
{
public static void printNumber ( int n )
{
while ( n != 0 ) {
Console.Write ( n % 10 );
n /= 10;
}
Console.WriteLine();
}
}
class ProgramDriver
{
public static void Main()
{
Print.printNumber ( 45678 );
}
}
Code: /* C code */
#include <stdio.h>
#include <stdlib.h>
void printNumber ( int n )
{
while ( n != 0 ) {
printf ( "%d", n % 10 );
n /= 10;
}
printf ( "\n" );
}
int main ( void )
{
printNumber ( 45678 );
return EXIT_SUCCESS;
}
Does anyone have ideas for a C# bracing style that works well? This textbook code just doesn't do it for me ( I hate textbook code ) Code: // Yucky yucky
class Print
{
public static void printNumber ( int n )
{
while ( n != 0 )
{
Console.Write ( n % 10 );
n /= 10;
}
Console.WriteLine();
}
}
-Prelude
__________________ My best code is written with the delete key. |
| Prelude is offline | |
| | #2 |
| Something Clever Join Date: Dec 2001
Posts: 187
| This looks ok, (quasi C++ style) Code:
class Print{
public static void printNumber ( int n ){
while ( n != 0 ) {
Console.Write ( n % 10 );
n /= 10;
}
Console.WriteLine();
}
}
|
| ginoitalo is offline | |
| | #3 |
| Guest
Posts: n/a
| Code:
class Print
{
public static void printNumber(int n)
{
while (n != 0)
{
Console.Write(n % 10);
n /= 10;
}
Console.WriteLine();
}
}
|
|
| | #4 | |
| Just one more wrong move. Join Date: Aug 2001
Posts: 3,232
| Quote:
__________________ Gays can't love like real people entropysink.com -- because arses weren't designed for running websites. | |
| -KEN- is offline | |
| | #5 |
| Registered User Join Date: Feb 2002 Location: Richmond, VA
Posts: 438
| Prelude, that's about the same code you'd use if doing the same thing in Java. It makes things much easier for a Java guy (like me) when the syntax is so similar. I'd structure the code like this... Code: using System;
class Print {
public static void printNumber(int n) {
while(n != 0) {
Console.Write(n % 10);
n /= 10;
}
Console.WriteLine();
}
}
class ProgramDriver {
public static void Main() {
Print.printNumber(45678);
}
}
|
| CompiledMonkey is offline | |
| | #6 |
| Sénior Member Join Date: Jan 2002
Posts: 982
| >Prelude, that's about the same code you'd use if doing the same thing in Java hmmm, I didn't realise Java imposed a particular style of code formating. |
| Sorensen is offline | |
| | #7 |
| Registered User Join Date: Feb 2002 Location: Richmond, VA
Posts: 438
| Not the format in particular, but the actual code itself. Just a few changes. Example, instead of "Console.Write(n % 10);" it would be "System.out.println(n % 10);". Most of the code from this certain app could be "ported" like that. |
| CompiledMonkey is offline | |
![]() |
| Thread Tools | |
| Display Modes | |
|
Similar Threads | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Mmmm beer | -JM | General Discussions | 10 | 08-05-2005 05:22 PM |
| Mmmm, thats good antifreeze! | RoD | A Brief History of Cprogramming.com | 1 | 04-03-2003 07:32 PM |
| text rpg adventure | BuRtAiNiAn FlY | Game Programming | 13 | 07-20-2002 02:25 PM |
| Checking for connected workstations. | Unregistered | Windows Programming | 3 | 06-22-2002 02:07 PM |
| IDE For C++ | zzido | Windows Programming | 5 | 05-23-2002 01:16 PM |