C# program to Illustrate Upper Triangular Matrix

Samual Sam
Updated on 17-Mar-2026 07:04:35

617 Views

An upper triangular matrix is a square matrix where all elements below the main diagonal are zero. In an upper triangular matrix, elements are preserved only on or above the main diagonal (where row index ≤ column index). Upper Triangular Matrix 1 2 3 4 0 5 6 7 0 0 8 9 0 0 0 10 Zero below diagonal Non-zero on/above diagonal Logic To display an upper triangular matrix, we use the condition i

What are user defined data types in C#?

Chandu yadav
Updated on 17-Mar-2026 07:04:35

3K+ Views

User-defined data types in C# allow developers to create custom types beyond the built-in primitive types. The main user-defined data types in C# are structures, enumerations, classes, interfaces, and delegates. This article focuses on structures and enumerations as fundamental user-defined types. Structure In C#, a structure is a value type data type that helps you group related data of various types into a single unit. The struct keyword is used for creating a structure. Syntax public struct StructName { // fields, properties, methods, constructors public dataType field1; ... Read More

How to iterate over a C# tuple?

Chandu yadav
Updated on 17-Mar-2026 07:04:35

2K+ Views

A tuple in C# is a data structure that holds multiple values of different types. Since tuples have a fixed structure, you cannot iterate over them using traditional loops like arrays or collections. Instead, you access tuple elements individually using their Item properties or through deconstruction. Syntax To create a tuple and access its elements − // Creating a tuple Tuple tuple = new Tuple(100, "Tom"); // Accessing individual elements tuple.Item1 // first element tuple.Item2 // second element For modern C# (7.0+), you can use tuple literals − var ... Read More

Func generic type in C#

Ankith Reddy
Updated on 17-Mar-2026 07:04:35

975 Views

The Func generic type in C# is a built-in delegate that represents a method which takes zero or more input parameters and returns a value. It provides a convenient way to store anonymous methods, lambda expressions, and regular methods that return a value. Syntax Following is the syntax for declaring a Func delegate − Func funcName; // No parameters, returns TResult Func funcName; ... Read More

C# Math.DivRem Method

karthikeya Boyini
Updated on 17-Mar-2026 07:04:35

292 Views

The Math.DivRem method in C# performs integer division and returns both the quotient and remainder in a single operation. This is more efficient than performing separate division and modulo operations when you need both results. Syntax Following is the syntax for the Math.DivRem method − public static int Math.DivRem(int a, int b, out int result); public static long Math.DivRem(long a, long b, out long result); Parameters a − The dividend (number to be divided) b − The divisor (number to divide by) result − An out parameter that receives the remainder ... Read More

Type.GetTypeHandle() Method in C#

AmitDiwan
Updated on 17-Mar-2026 07:04:35

136 Views

The Type.GetTypeHandle() method in C# is used to get the runtime type handle for a specified object. A RuntimeTypeHandle provides a lightweight way to reference a type without holding a direct reference to the Type object itself, which is useful in performance-critical scenarios and interop operations. Syntax Following is the syntax for the Type.GetTypeHandle() method − public static RuntimeTypeHandle GetTypeHandle(object o) Parameters o − The object for which to get the type handle. Return Value Returns a RuntimeTypeHandle structure that represents the type of the specified object. Using ... Read More

C# Program to Kill a Thread

karthikeya Boyini
Updated on 17-Mar-2026 07:04:35

1K+ Views

In C#, a thread can be gracefully stopped using a flag-based approach rather than forcibly terminating it. This method allows the thread to complete its current work and exit cleanly by checking a boolean flag in its loop condition. The recommended approach involves setting a boolean flag that the thread periodically checks. When you want to stop the thread, you set the flag to true, causing the thread's loop to exit naturally. Syntax Following is the syntax for creating and controlling a thread with a stop flag − Thread thread = new Thread(methodName); thread.Start(); ... Read More

How do I determine the size of my array in C#

seetha
Updated on 17-Mar-2026 07:04:35

270 Views

In C#, determining the size of an array is accomplished using the Length property. This property returns the total number of elements in the array as an int value. Syntax Following is the syntax for getting array length − arrayName.Length Parameters The Length property does not take any parameters and returns an integer representing the number of elements. Return Value Returns an int value indicating the total number of elements in the array. Using Length Property for Single-Dimensional Arrays For single-dimensional arrays, the Length property provides a direct count ... Read More

Type.GetFields() Method in C#

AmitDiwan
Updated on 17-Mar-2026 07:04:35

376 Views

The Type.GetFields() method in C# is used to retrieve the fields of the current Type using reflection. This method returns an array of FieldInfo objects representing the fields that match the specified binding criteria. Fields are data members of a class that store values. The GetFields() method allows you to examine both public and non-public fields at runtime, making it useful for inspection, debugging, and dynamic programming scenarios. Syntax Following is the syntax for the parameterless overload − public System.Reflection.FieldInfo[] GetFields(); Following is the syntax for the overload with binding flags − ... Read More

C# Program to pass Parameter to a Thread

Samual Sam
Updated on 17-Mar-2026 07:04:35

5K+ Views

To work with threads in C#, you need to add the System.Threading namespace. Passing parameters to threads allows you to send data from the main thread to worker threads, enabling more flexible and dynamic thread operations. Syntax Following is the syntax for creating a thread and passing a parameter − Thread thread = new Thread(ThreadMethod); thread.Start(parameter); The thread method must accept an object parameter − static void ThreadMethod(object parameter) { // cast parameter to appropriate type } Using Thread.Start() with a Parameter The Thread.Start(object) method accepts ... Read More

Advertisements