Csharp Articles

Page 117 of 196

How to print a diamond using nested loop using C#?

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

A diamond pattern is a common programming exercise that demonstrates the use of nested loops in C#. The diamond shape consists of two parts: an upper triangle that expands and a lower triangle that contracts. To create a diamond pattern, you need to consider three key elements − Number of rows (determines diamond size) Characters to display (commonly $ or *) Leading spaces for alignment Diamond Pattern Structure Upper Triangle Row 1: 4 spaces + 1 char Row 2: 3 spaces + ...

Read More

How to print a line on the console using C#?

Chandu yadav
Chandu yadav
Updated on 17-Mar-2026 828 Views

To display a line on the console in C#, we use the Console.WriteLine() method. This method prints text to the console and automatically adds a new line at the end. Syntax Following is the syntax for printing a line to the console − Console.WriteLine(value); Where value can be a string, variable, or any expression that can be converted to a string. Using Console.WriteLine() with Strings The most common use is to print string literals or string variables − using System; public class Program { public static ...

Read More

How to print multiple blank lines in C#?

George John
George John
Updated on 17-Mar-2026 884 Views

In C#, there are several ways to print multiple blank lines to the console. You can use loops, string repetition, or direct method calls depending on your needs. Using a While Loop The most straightforward approach is to use a while loop to print blank lines repeatedly − using System; namespace Program { public class Demo { public static void Main(string[] args) { int a = 0; while ...

Read More

C# program to get max occurred character in a String

karthikeya Boyini
karthikeya Boyini
Updated on 17-Mar-2026 950 Views

To find the maximum occurred character in a string in C#, we need to count the frequency of each character and then identify which character appears most frequently. This can be achieved using different approaches including character arrays and dictionaries. Syntax Using a character frequency array − int[] frequency = new int[256]; // ASCII characters for (int i = 0; i < str.Length; i++) frequency[str[i]]++; Using a dictionary for character counting − Dictionary charCount = new Dictionary(); foreach (char c in str) { charCount[c] ...

Read More

Understanding Logistic Regression in C#

karthikeya Boyini
karthikeya Boyini
Updated on 17-Mar-2026 484 Views

Logistic regression is a statistical method used for binary classification problems. Unlike linear regression which predicts continuous values, logistic regression predicts the probability that an instance belongs to a particular category. It is widely used in medical science to predict disease outcomes and in business to forecast customer behavior. The key advantage of logistic regression is that it produces probabilities between 0 and 1, making it ideal for classification tasks. It also provides interpretable results through odds ratios and supports statistical hypothesis testing. Mathematical Foundation Logistic regression uses a linear model combined with the logistic function (sigmoid ...

Read More

How to check if an item exists in a C# list collection?

Arjun Thakur
Arjun Thakur
Updated on 17-Mar-2026 14K+ Views

In C#, you can check if an item exists in a List collection using several methods. The most common approach is the Contains() method, which returns true if the item is found and false otherwise. Syntax Following is the syntax for the Contains() method − bool Contains(T item) Parameters item − The object to locate in the list. The value can be null for reference types. Return Value Returns true if the item is found in the list; otherwise, false. Using Contains() Method Example using ...

Read More

How to find a matching substring using regular expression in C#?

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

Regular expressions in C# provide a powerful way to search for specific patterns within strings. The Regex.Matches() method from the System.Text.RegularExpressions namespace allows you to find all occurrences of a pattern in a string. To find a matching substring, you create a regex pattern and use it to search through your target string. The pattern can be a simple literal match or include special regex metacharacters for more complex searches. Syntax Following is the basic syntax for finding matches using regular expressions − MatchCollection matches = Regex.Matches(inputString, pattern); For word boundary matching, use ...

Read More

Formatted output in C#

George John
George John
Updated on 17-Mar-2026 2K+ Views

In C#, formatted output allows you to control how data is displayed when converting values to strings. This is essential for presenting numbers, dates, and other data types in a user-friendly format using format specifiers and the String.Format() method. Syntax Following is the syntax for basic string formatting − String.Format("{index:format}", value) Where index is the parameter position (starting from 0) and format is the format specifier. Using Format Specifiers for Numbers Decimal Places and Thousands Separator using System; class Demo { public static void Main(String[] ...

Read More

C# program to print duplicates from a list of integers

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

To print duplicates from a list of integers in C#, you can use several approaches. The most common method involves using a Dictionary to count occurrences of each element, then filtering elements that appear more than once. Using Dictionary with ContainsKey This approach uses a Dictionary to store each number and its count. The ContainsKey method checks if a number already exists in the dictionary − using System; using System.Collections.Generic; class Program { public static void Main() { int[] arr = { 3, ...

Read More

How to convert a list to string in C#?

Ankith Reddy
Ankith Reddy
Updated on 17-Mar-2026 3K+ Views

In C#, you can convert a List to a string using various methods. The most common and efficient approach is using the string.Join() method, which concatenates all elements of a list into a single string with a specified delimiter. Syntax Following is the syntax for converting a list to string using string.Join() − string result = string.Join(delimiter, list); Where delimiter is the separator between elements, and list is your List collection. Using string.Join() Method The string.Join() method is the most efficient way to convert a list to string. It accepts a delimiter ...

Read More
Showing 1161–1170 of 1,951 articles
« Prev 1 115 116 117 118 119 196 Next »
Advertisements