using System.Data.SqlClient;
public static void Main()
Console.WriteLine("=== Spørgsmål 1 ===");
ReverseString("hello world");
Console.WriteLine("\n=== Spørgsmål 2 ===");
ReverseWordOrder("Diviso at job a like would I");
Console.WriteLine("\n=== Spørgsmål 3 ===");
RotateRight(new int[] { 1, 2, 3, 4, 5 });
Console.WriteLine("\n=== Spørgsmål 4 ===");
FindSecondLargeInArray(new int[] { 1, 2, 3, 4, 5 });
Console.WriteLine("\n=== Spørgsmål 5 ===");
SingleToMulti(new int[] { 1, 2, 3, 4, 5, 6 }, 2, 3);
Console.WriteLine("\n=== Bonus Spørgsmål ===");
Console.WriteLine($"Der opstod en fejl: {ex.Message}");
internal static void ReverseString(string str)
char[] charArray = str.ToCharArray();
Array.Reverse(charArray);
string reversed = new string(charArray);
Console.WriteLine($"Original: {str} | Vendt om: {reversed}");
internal static void ReverseWordOrder(string str)
string[] words = str.Split(' ');
Console.WriteLine($"Original: {str} | Vendt rækkefølge: {string.Join(" ", words)}");
internal static void RotateRight(int[] array)
if (array.Length == 0) return;
int lastElement = array[^1];
for (int i = array.Length - 1; i > 0; i--)
Console.WriteLine($"Roteret array: {string.Join(", ", array)}");
internal static void FindSecondLargeInArray(int[] arr)
Console.WriteLine("Arrayet skal indeholde mindst to elementer.");
int largest = int.MinValue, secondLargest = int.MinValue;
else if (num > secondLargest && num < largest)
Console.WriteLine($"Næsthøjeste tal: {secondLargest}");
internal static void SingleToMulti(int[] array, int row, int column)
if (array.Length != row * column)
Console.WriteLine("Dimensionerne matcher ikke arrayets størrelse.");
Console.WriteLine("2D Array:");
for (int i = 0; i < row; i++)
for (int j = 0; j < column; j++)
Console.Write(array[i * column + j] + " ");
internal static void BonusQuestionSql()
string connectionString = "Server=mssql-23833-0.cloudclusters.net,23833;Database=devtest;TrustServerCertificate=True;user=devtest;Password=devtest1234";
C.firstname + ' ' + C.lastname AS CustomerName,
O.createDate AS OrderDate,
SELECT SUM(price * quantity)
WHERE orderID = O.ID AND deletedOn IS NULL
JOIN tblCustomer C ON O.customerID = C.ID
WHERE O.deletedOn IS NULL AND C.deletedOn IS NULL
using var connection = new SqlConnection(connectionString);
using var command = new SqlCommand(query, connection);
using var reader = command.ExecuteReader();
Console.WriteLine("OrdreID | Kunde Navn | Ordre Dato | Ordre Total");
Console.WriteLine("---------------------------------------------------");
Console.WriteLine($"{reader["OrderID"]} | {reader["CustomerName"]} | {reader["OrderDate"]:yyyy-MM-dd} | {reader["OrderTotal"]}");
Console.WriteLine($"SQL Fejl: {ex.Message}");
Console.WriteLine($"Uventet fejl: {ex.Message}");