// '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.