Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
-
Economics & Finance
Articles by karthikeya Boyini
Page 25 of 143
How to convert a number from Decimal to Binary using recursion in C#?
Converting a decimal number to binary using recursion in C# involves repeatedly dividing the number by 2 and collecting the remainders. The recursive approach breaks down the problem into smaller subproblems until the base case is reached. Syntax Following is the basic syntax for the recursive binary conversion method − public void ConvertToBinary(int decimalNumber) { if (decimalNumber > 0) { ConvertToBinary(decimalNumber / 2); Console.Write(decimalNumber % 2); } } How It ...
Read MoreHow to remove an empty string from a list of empty strings in C#?
In C#, you can remove empty strings from a list using several methods. Empty strings can be truly empty ("") or contain only whitespace characters (" "). This article demonstrates different approaches to remove these empty or whitespace-only strings from a list. Syntax Using RemoveAll() method to remove empty strings − list.RemoveAll(string.IsNullOrEmpty); Using RemoveAll() with lambda expression to remove empty and whitespace strings − list.RemoveAll(x => string.IsNullOrWhiteSpace(x)); Using LINQ Where() method to filter out empty strings − var filteredList = list.Where(x => !string.IsNullOrEmpty(x)).ToList(); Using RemoveAll() Method ...
Read MoreHow to Convert Hex String to Hex Number in C#?
In C#, converting a hexadecimal string to its numeric value is a common operation. Hexadecimal strings represent numbers in base 16 using digits 0-9 and letters A-F. C# provides several methods to convert hex strings to different numeric types depending on your needs. Syntax Following is the syntax for converting hex strings using different methods − Convert.ToInt32(hexString, 16) Convert.ToSByte(hexString, 16) int.Parse(hexString, NumberStyles.HexNumber) Using Convert.ToInt32() Method The most commonly used method is Convert.ToInt32() which converts a hex string to a 32-bit signed integer − using System; public class Program { ...
Read MoreHow to convert a 2D array into 1D array in C#?
Converting a 2D array to a 1D array in C# involves flattening the multi-dimensional structure into a single-dimensional array. This process is commonly used in scenarios like matrix operations, data serialization, or when interfacing with APIs that expect 1D arrays. Using Nested Loops The most straightforward approach is using nested loops to iterate through the 2D array and copy elements to the 1D array − using System; class Program { static void Main(string[] args) { int[, ] a = new int[2, 2] {{1, ...
Read MoreC# program to check whether a given string is Heterogram or not
A Heterogram is a string that contains no duplicate letters. Each character in the string appears exactly once. For example, words like "mobile", "cry", and "laptop" are heterograms because no letter is repeated. Examples of Heterograms mobile - No repeated letters cry - All unique letters laptop - Each letter appears once Algorithm The algorithm uses an integer array to track which letters have been encountered. For each character in the string − Convert the character to an array index using str[i] - ...
Read MoreHow to use #undef directive in C#?
The #undef directive in C# allows you to undefine a previously defined symbol, making it unavailable for use in conditional compilation directives like #if. This is useful for controlling which code sections are included during compilation. Syntax Following is the syntax for using the #undef directive − #undef SYMBOL Where SYMBOL is the identifier you want to undefine. For example − #undef DEBUG #undef TESTING Key Rules The #undef directive must appear at the top of the file, before any code or using statements. You ...
Read MoreHow to print a blank line in C#?
To print a blank line in C#, you can use several methods. The most common approach is using Console.WriteLine() without any parameters, which outputs an empty line to the console. Syntax Following are the different ways to print a blank line − Console.WriteLine(); // Empty line Console.WriteLine(""); // Empty string Console.WriteLine(" "); // Single space Console.Write(""); // Newline character ...
Read MoreHow to create a Dictionary using C#?
A Dictionary in C# is a collection of key-value pairs where each key is unique. The Dictionary class is part of the System.Collections.Generic namespace and provides fast lookups based on keys. Dictionaries are useful when you need to associate values with unique identifiers, such as storing employee IDs with names or product codes with prices. Syntax Following is the syntax for creating a Dictionary − Dictionary dictionaryName = new Dictionary(); Following is the syntax for adding items to a Dictionary − dictionaryName.Add(key, value); dictionaryName[key] = value; // Alternative syntax ...
Read MoreC# program to get max occurred character in a String
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 MoreUnderstanding Logistic Regression in C#
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