using System; public class Factorial { public static int Calculate(int n) { if(n == 0) return 1; else return n * Calculate(n - 1); } public static void Main() { Console.WriteLine("Enter a number: "); int num = int.Parse(Console.ReadLine()); int result = Calculate(num); Console.WriteLine("Factorial of {0} is {1}", num, result); } }
using System; using System.Collections.Generic; using System.Linq; public class Program { public static void Main() { ListThis code example uses LINQ to sort a list of integers in descending order. The program creates a list of integers and then uses LINQ's `OrderByDescending` method to sort the list in descending order. The sorted list is then printed to the console. This code uses the System and System.Linq package libraries.numbers = new List { 5, 2, 8, 3, 1 }; var sortedNumbers = numbers.OrderByDescending(n => n).ToList(); foreach (var num in sortedNumbers) { Console.WriteLine(num); } } }