This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| using System; | |
| using System.Threading.Tasks; | |
| public class Program | |
| { | |
| public static void Main() | |
| { | |
| Console.WriteLine("Starting main method."); | |
| LogApiCall("API endpoint called."); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /// <summary> | |
| /// Calculates the factorial of a given non-negative integer using a recursive approach. | |
| /// </summary> | |
| /// <param name="number">The non-negative integer for which the factorial is to be calculated.</param> | |
| /// <returns>The factorial of the given number.</returns> | |
| /// <exception cref="ArgumentException">Thrown when the provided number is negative.</exception> | |
| public static int CalculateFactorial(int number) | |
| { | |
| if (number < 0) | |
| { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /// <summary> | |
| /// Recursively searches for a file with the specified name within a directory and its subdirectories. | |
| /// </summary> | |
| /// <param name="directoryPath">The path of the directory to start the search from.</param> | |
| /// <param name="fileName">The name of the file to search for.</param> | |
| /// <returns>The full path of the found file or null if the file is not found.</returns> | |
| public static string FindFileInDirectory(string directoryPath, string fileName) | |
| { | |
| if (string.IsNullOrWhiteSpace(directoryPath) || string.IsNullOrWhiteSpace(fileName)) | |
| { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /// <summary> | |
| /// Computes the nth Fibonacci number using a recursive approach. | |
| /// </summary> | |
| /// <param name="n">The position of the Fibonacci number to compute.</param> | |
| /// <returns>The nth Fibonacci number.</returns> | |
| public static int ComputeFibonacci(int n) | |
| { | |
| if (n < 0) | |
| { | |
| throw new ArgumentOutOfRangeException(nameof(n), "Input must be a non-negative integer."); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public static int FindMaximumValue(int[] numbers, int startIndex, int endIndex) | |
| { | |
| // Base case: If the array has only one element, return that element. | |
| if (startIndex == endIndex) | |
| return numbers[startIndex]; | |
| int middleIndex = (startIndex + endIndex) / 2; | |
| int leftMax = FindMaximumValue(numbers, startIndex, middleIndex); | |
| int rightMax = FindMaximumValue(numbers, middleIndex + 1, endIndex); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /// <summary> | |
| /// Calculates the sum of elements in a list between two indices using recursion. | |
| /// </summary> | |
| /// <param name="numbers">The list of numbers.</param> | |
| /// <param name="startIndex">The starting index for the sum.</param> | |
| /// <param name="endIndex">The ending index for the sum.</param> | |
| /// <param name="accumulatedSum">The current accumulated sum (used for recursion).</param> | |
| /// <returns>The sum of elements between the specified indices.</returns> | |
| public static int CalculateSumBetweenIndices(List<int> numbers, int startIndex, int endIndex, int accumulatedSum = 0) | |
| { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public static string ReverseString(string input) | |
| { | |
| int length = input.Length; | |
| char[] charArray = new char[length]; | |
| for (int i = 0; i < length; i++) | |
| { | |
| charArray[i] = input[length - 1 - i]; | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| | Method | Mean | Error | StdDev | | |
| |---------------------- |----------:|---------:|---------:| | |
| | ReverseUsingCharArray | 55.24 ns | 1.167 ns | 1.747 ns | | |
| | ReverseUsingLinq | 388.46 ns | 7.526 ns | 8.365 ns | | |
| public class StringReversalBenchmarks | |
| { | |
| private const string TestString = "This is a test string for benchmarking purposes."; | |
| [Benchmark] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| MERGE INTO target_table AS target | |
| USING source_table AS source | |
| ON target.id = source.id | |
| WHEN MATCHED THEN | |
| UPDATE SET target.column1 = source.column1, target.column2 = source.column2 | |
| WHEN NOT MATCHED THEN | |
| INSERT (id, column1, column2) VALUES (source.id, source.column1, source.column2); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // And the client-side JavaScript to connect to this hub: | |
| const connection = new signalR.HubConnectionBuilder() | |
| .withUrl("/chatHub") | |
| .build(); | |
| connection.on("ReceiveMessage", function (message) { | |
| console.log("New message: " + message); | |
| }); | |
| connection.start(); |