fork download
  1. using System;
  2. using System.Threading;
  3.  
  4. class Program
  5. {
  6. static void Main()
  7. {
  8. // Array to be used by the first thread
  9. int[] arr = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
  10.  
  11. // Default string to be reversed
  12. string input = "DefaultString"; // You can change this value
  13.  
  14. // Create and start threads
  15. Thread t1 = new Thread(() => CalculateSquares(arr));
  16. Thread t2 = new Thread(() => ReverseString(input));
  17.  
  18. t1.Start();
  19. t2.Start();
  20.  
  21. // Wait for both threads to finish
  22. t1.Join();
  23. t2.Join();
  24. }
  25.  
  26. // Method to calculate and print squares of array elements
  27. static void CalculateSquares(int[] arr)
  28. {
  29. Console.WriteLine("Original Array: " + string.Join(", ", arr));
  30. Console.Write("Squares of Array Elements: ");
  31. foreach (int number in arr)
  32. {
  33. Console.Write(number * number + " ");
  34. }
  35. Console.WriteLine();
  36. }
  37.  
  38. // Method to reverse a string
  39. static void ReverseString(string str)
  40. {
  41. char[] charArray = str.ToCharArray();
  42. Array.Reverse(charArray);
  43. string reversed = new string(charArray);
  44. Console.WriteLine($"Original String: {str}");
  45. Console.WriteLine($"Reversed String: {reversed}");
  46. }
  47. }
  48.  
Success #stdin #stdout 0.04s 29096KB
stdin
Standard input is empty
stdout
Original Array: 1, 2, 3, 4, 5, 6, 7, 8, 9, 10
Squares of Array Elements: 1 4 9 16 25 36 49 64 81 100 
Original String: DefaultString
Reversed String: gnirtStluafeD