Skip to main content
replaced http://stackoverflow.com/ with https://stackoverflow.com/
Source Link
deleted 16 characters in body
Source Link
Nathan Merrill
  • 14.5k
  • 30
  • 61
// 'complete program' reading input from command line arguments ('argv') and writingreturning tovia STDOUTexit code
static voidint Main(string[]args)
{
    int n=int.Parse(args[0]), // read an integer
        a=1; // accumulator

    for(;n>0;)
        a*=n--;
 
    System.Console.WriteLine(a);return a;
}
// 'complete program' reading input from command line arguments ('argv') and writing to STDOUT
static void Main(string[]args)
{
    int n=int.Parse(args[0]), // read an integer
        a=1; // accumulator

    for(;n>0;)
        a*=n--;
 
    System.Console.WriteLine(a);
}
// 'complete program' reading input from command line arguments ('argv') and returning via exit code
static int Main(string[]args)
{
    int n=int.Parse(args[0]), // read an integer
        a=1; // accumulator

    for(;n>0;)
        a*=n--;
    return a;
}
Thank you Peter
Source Link
VisualMelon
  • 3.9k
  • 10
  • 10
// 'complete program' reading input from STDIN, writing output to STDOUT
static void Main()
{
    int n=int.Parse(System.Console.ReadLine()), // read an integer
        a=1; // accumulator

    for(;n>0;)
        a*=n--;

    System.Console.WriteLine(a);
}
 
 
// 'complete program' reading input from command line arguments ('argv') and writing to STDOUT
static void Main(string[]args)
{
    int n=int.Parse(args[0]), // read an integer
        a=1; // accumulator

    for(;n>0;)
        a*=n--;

    System.Console.WriteLine(a);
}
 
 
// recursive named function
int F(int n)
{
    return n>1?F(n)*n:1;
}
 
 
// recursive named function (C# 6 'expression bodied' syntax)
int F(int n)=>n>1?F(n)*n:1;
 
 
// iterative anonymous typed lambda expression
(int n)=>
{
    int a=1;

    for(;n>0;n--)
        a*=n;

    return a;
}
 
 
// recursive named lambda expression (these are of no use in C# golfing)
System.Func<int,int>F=null;
F=n=>
{
    int a=1;

    forF=n=>n>1?F(;n>0;n--n)
        a*=n;

    return a;
};*n:1;

In C#/.NET, truthiness and falseness are defined by the true and false operators, which (unless you define them on your own classes) are only defined for the true and falsebool constantsdata type.

If you are asked to produce a truth/falsy value then it must be something you could use in an if statement, which would be the bool values true, and false, or a manually defined class (but this is unlikely ever to appear in code-golf). You can't, for example, return 1 for true, and 0 for false, unless the challenge explicitly allows you to.

// 'complete program' reading input from STDIN, writing output to STDOUT
static void Main()
{
    int n=int.Parse(System.Console.ReadLine()), // read an integer
        a=1; // accumulator

    for(;n>0;)
        a*=n--;

    Console.WriteLine(a);
}
 
// 'complete program' reading input from command line arguments ('argv') and writing to STDOUT
static void Main(string[]args)
{
    int n=int.Parse(args[0]), // read an integer
        a=1; // accumulator

    for(;n>0;)
        a*=n--;

    Console.WriteLine(a);
}
 
// recursive named function
int F(int n)
{
    return n>1?F(n)*n:1;
}
 
// recursive named function (C# 6 'expression bodied' syntax)
int F(int n)=>n>1?F(n)*n:1;
 
// iterative anonymous typed lambda expression
(int n)=>
{
    int a=1;

    for(;n>0;n--)
        a*=n;

    return a;
}
 
// recursive named lambda expression (these are of no use in C# golfing)
System.Func<int,int>F=null;
F=n=>
{
    int a=1;

    for(;n>0;n--)
        a*=n;

    return a;
};

In C#/.NET, truthiness and falseness are defined by the true and false operators, which (unless you define them on your own classes) are only defined for the true and false constants.

If you are asked to produce a truth/falsy value then it must be something you could use in an if statement, which would be true, false, or a manually defined class (but this is unlikely ever to appear in code-golf). You can't, for example return 1 for true, and 0 for false unless the challenge explicitly allows you to.

// 'complete program' reading input from STDIN, writing output to STDOUT
static void Main()
{
    int n=int.Parse(System.Console.ReadLine()), // read an integer
        a=1; // accumulator

    for(;n>0;)
        a*=n--;

    System.Console.WriteLine(a);
}
 
// 'complete program' reading input from command line arguments ('argv') and writing to STDOUT
static void Main(string[]args)
{
    int n=int.Parse(args[0]), // read an integer
        a=1; // accumulator

    for(;n>0;)
        a*=n--;

    System.Console.WriteLine(a);
}
 
// recursive named function
int F(int n)
{
    return n>1?F(n)*n:1;
}
 
// recursive named function (C# 6 'expression bodied' syntax)
int F(int n)=>n>1?F(n)*n:1;
 
// iterative anonymous typed lambda expression
(int n)=>
{
    int a=1;

    for(;n>0;n--)
        a*=n;

    return a;
}
 
// recursive named lambda expression (these are of no use in C# golfing)
System.Func<int,int>F=null;
F=n=>n>1?F(n)*n:1;

In C#/.NET, truthiness and falseness are defined by the true and false operators, which (unless you define them on your own classes) are only defined for the bool data type.

If you are asked to produce a truth/falsy value then it must be something you could use in an if statement, which would be the bool values true and false, or a manually defined class (but this is unlikely ever to appear in code-golf). You can't, for example, return 1 for true and 0 for false, unless the challenge explicitly allows you to.

Syntax Highlighting
Source Link
VisualMelon
  • 3.9k
  • 10
  • 10
Loading
Grammar fixes/clarifications
Source Link
DLosc
  • 39.2k
  • 33
  • 49
Loading
Source Link
VisualMelon
  • 3.9k
  • 10
  • 10
Loading
Post Made Community Wiki by VisualMelon