Samual Sam

Samual Sam

1,507 Articles Published

Articles by Samual Sam

Page 13 of 151

What are control statements in C#?

Samual Sam
Samual Sam
Updated on 17-Mar-2026 7K+ Views

Control statements in C# determine the flow of program execution by specifying which code blocks to execute based on conditions or how many times to repeat certain operations. These statements are fundamental building blocks that allow developers to create dynamic and responsive applications. C# provides several types of control statements that can be categorized into conditional statements (if, if-else, switch) and loop statements (for, while, do-while, foreach). Let's explore the main control statements with practical examples. if Statement An if statement executes a block of code only when a specified boolean condition evaluates to true. Syntax ...

Read More

String format for DateTime in C#

Samual Sam
Samual Sam
Updated on 17-Mar-2026 510 Views

The String.Format method in C# provides powerful formatting capabilities for DateTime objects. You can use various format specifiers to display dates and times in different formats, from simple year displays to complex custom patterns. Syntax Following is the syntax for formatting DateTime using String.Format − String.Format("{0:format_specifier}", dateTimeObject) Common format specifiers include − y − Year (1 digit minimum) yy − Year (2 digits) yyyy − Year (4 digits) M − Month (1-12) MM − Month (01-12) MMM − Month abbreviation (Jan, Feb, etc.) MMMM − Full month name (January, February, etc.) d ...

Read More

Unit Testing for C# Code

Samual Sam
Samual Sam
Updated on 17-Mar-2026 1K+ Views

Unit testing is a fundamental practice in C# development that helps maintain code quality throughout the development process. It allows developers to identify problems early in the development cycle and ensures code reliability and reusability. One of the key principles of effective unit testing is following Test Driven Development (TDD) approach, where you write test cases first, then write the minimal code required to make those tests pass. Setting Up Unit Tests in Visual Studio For unit testing in C#, you can use Microsoft's built-in testing framework, commonly known as MS Unit Test. Here's how to create ...

Read More

Merge two arrays using C# AddRange() method

Samual Sam
Samual Sam
Updated on 17-Mar-2026 3K+ Views

The AddRange() method in C# is used to add elements from a collection to the end of a List. This method is particularly useful for merging arrays by first converting them to a list, adding both arrays using AddRange(), and then converting the result back to an array. Syntax Following is the syntax for the AddRange() method − public void AddRange(IEnumerable collection) Parameters collection − The collection whose elements should be added to the end of the List. The collection itself cannot be null, but it can contain elements that are null. ...

Read More

What are different methods of passing parameters in C#?

Samual Sam
Samual Sam
Updated on 17-Mar-2026 520 Views

When a method with parameters is called, you need to pass the parameters to the method using one of the following three methods in C# − Value Parameters (Default) This method copies the actual value of an argument into the formal parameter of the function. Changes made to the parameter inside the function have no effect on the original argument because the method works with a copy of the value. Value Parameters - Copy by Value Main Method int a = 7 int b ...

Read More

Represent Int32 as a Hexadecimal String in C#

Samual Sam
Samual Sam
Updated on 17-Mar-2026 5K+ Views

To represent Int32 as a hexadecimal string in C#, you can use several methods. The most common approaches are using Convert.ToString() with base 16, or using the ToString() method with hexadecimal format specifiers. Int32 represents a 32-bit signed integer that can hold values from -2, 147, 483, 648 to 2, 147, 483, 647. Converting these values to hexadecimal format is useful for debugging, display purposes, and when working with low-level operations. Using Convert.ToString() with Base 16 The Convert.ToString() method accepts a base parameter. Setting it to 16 converts the integer to its hexadecimal representation − ...

Read More

SortedMap Interface in C#

Samual Sam
Samual Sam
Updated on 17-Mar-2026 616 Views

In C#, there is no direct equivalent to Java's SortedMap interface. However, C# provides the SortedList and SortedDictionary collections which offer similar functionality for maintaining key-value pairs in sorted order. The SortedList collection in C# uses both a key and an index to access items. It combines the features of an array and a hash table, maintaining items in sorted order based on the key values. You can access items either by index (like an ArrayList) or by key (like a Hashtable). Syntax Following is the syntax for creating a SortedList − SortedList sortedList = ...

Read More

Print Single and Multiple variable in C#

Samual Sam
Samual Sam
Updated on 17-Mar-2026 10K+ Views

In C#, displaying variable values to the console is fundamental for debugging and output purposes. You can print single or multiple variables using various methods with Console.WriteLine(). Syntax Following is the syntax for printing a single variable − Console.WriteLine(variable); Console.WriteLine("Text: " + variable); Following is the syntax for printing multiple variables − Console.WriteLine("Values: {0} {1}", var1, var2); Console.WriteLine($"Values: {var1} {var2}"); Printing a Single Variable You can print a single variable by passing it directly to Console.WriteLine() or by concatenating it with text using the + operator − ...

Read More

C# program to list the difference between two lists

Samual Sam
Samual Sam
Updated on 17-Mar-2026 2K+ Views

To find the difference between two lists in C#, you can use the Except() method from LINQ. This method returns elements from the first list that are not present in the second list, effectively giving you the set difference. Syntax Following is the syntax for using Except() method to find list difference − IEnumerable result = list1.Except(list2); Where list1 is the source list and list2 contains elements to exclude from the result. Using Except() Method The Except() method performs a set difference operation, returning elements that exist in the first collection but ...

Read More

C# program to check if a value is in an array

Samual Sam
Samual Sam
Updated on 17-Mar-2026 1K+ Views

Use the Array.Exists method to check if a value is in an array or not. This method returns a boolean value indicating whether the specified element exists in the array. Syntax Following is the syntax for Array.Exists method − public static bool Exists(T[] array, Predicate match) Parameters array − The one-dimensional array to search. match − A predicate that defines the conditions of the element to search for. Return Value Returns true if the array contains an element that matches the conditions defined by the ...

Read More
Showing 121–130 of 1,507 articles
« Prev 1 11 12 13 14 15 151 Next »
Advertisements