Server Side Programming Articles

Page 758 of 2109

C# program to check if binary representation is palindrome

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

A binary palindrome is a number whose binary representation reads the same forwards and backwards. To check if a number's binary representation is a palindrome, we need to reverse its binary form and compare it with the original. For example, the number 5 has binary representation 101, which reads the same forwards and backwards, making it a binary palindrome. How It Works The algorithm uses bitwise operations to reverse the binary representation − Left shift (=) moves bits to the right, effectively dividing by 2 AND operation (&) checks if the least ...

Read More

C# program to check if there are K consecutive 1's in a binary number

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

A C# program to check if there are K consecutive 1's in a binary number involves counting the longest sequence of consecutive 1's and comparing it with the required count K. This is useful for binary pattern analysis and digital signal processing applications. Approach The algorithm iterates through the binary array, maintaining a counter for consecutive 1's. When a 0 is encountered, the counter resets. The maximum consecutive count is tracked using Math.Max() method. Using Boolean Array Representation A binary number can be represented as a boolean array where true represents 1 and false represents 0 ...

Read More

C# program to check if a Substring is present in a Given String

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

The Contains() method in C# is used to check if a substring is present within a given string. It returns a boolean value − true if the substring is found, and false otherwise. Syntax Following is the syntax for the Contains() method − bool result = string.Contains(substring); Parameters substring − The string to search for within the main string. Return Value The Contains()

Read More

C# program to check if string is panagram or not

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

A pangram is a sentence that contains all 26 letters of the English alphabet at least once. The word "pangram" comes from Greek, meaning "all letters". A famous example is "The quick brown fox jumps over the lazy dog". In C#, we can check if a string is a pangram by converting it to lowercase, filtering only alphabetic characters, and counting the distinct letters present. Syntax The basic approach uses LINQ methods to process the string − string.ToLower().Where(ch => Char.IsLetter(ch)).GroupBy(ch => ch).Count() This checks if the count of distinct letters equals 26. ...

Read More

C# Example for Single Inheritance

karthikeya Boyini
karthikeya Boyini
Updated on 17-Mar-2026 4K+ Views

Single inheritance in C# allows a derived class to inherit from only one base class. This is the most common form of inheritance where a child class extends the functionality of its parent class by inheriting all accessible members and adding its own specific methods or properties. Syntax Following is the syntax for single inheritance in C# − class BaseClass { // base class members } class DerivedClass : BaseClass { // derived class members // inherits all accessible members from BaseClass } ...

Read More

C# Generics vs C++ Templates

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

C# Generics and C++ Templates both provide support for parameterized types, allowing you to write reusable code that works with different data types. However, they differ significantly in their design philosophy, capabilities, and implementation approaches. Key Differences Between C# Generics and C++ Templates Feature C# Generics C++ Templates Compilation Model Compile-time and run-time support Compile-time only Type Safety Strong type checking at compile-time Duck typing, errors at instantiation Specialization No explicit or partial specialization Full support for specialization Non-type Parameters Not supported Fully supported ...

Read More

C# Multiple Local Variable Declarations

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

In C#, you can declare and initialize multiple local variables of the same type in a single statement using the comma operator. This provides a concise way to declare several variables at once, making your code more readable and reducing repetition. Syntax Following is the syntax for declaring multiple local variables of the same type − dataType variable1 = value1, variable2 = value2, variable3 = value3; You can also declare variables without initialization − dataType variable1, variable2, variable3; Basic Multiple Variable Declaration The following example demonstrates declaring four integer ...

Read More

C# program to check for URL in a String

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

In C#, you can check for URLs in a string using various methods such as StartsWith() for simple prefix matching or regular expressions for more comprehensive URL validation. The StartsWith() method is useful when you need to verify if a string begins with a specific URL pattern. Syntax Following is the syntax for using StartsWith() to check URL prefixes − string.StartsWith("url_prefix") For checking multiple URL patterns, you can combine conditions using logical operators − if (input.StartsWith("https://www.") || input.StartsWith("https://")) { // URL found } Using StartsWith() for Simple ...

Read More

C# program to check if a string contains any special character

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

To check if a string contains any special character in C#, you can use the Char.IsLetterOrDigit method. This method returns false for any character that is not a letter or digit, which means it's a special character. Special characters include symbols like @, #, $, %, &, punctuation marks, and whitespace characters that are not alphanumeric. Syntax Following is the syntax for checking if a character is a letter or digit − bool Char.IsLetterOrDigit(char c) To check for special characters, use the negation operator − if (!Char.IsLetterOrDigit(character)) { ...

Read More

C# program to check password validity

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

While creating a password, you may have seen validation requirements on websites that ensure a password is strong and secure. Common password requirements include − Minimum 8 characters and maximum 14 characters At least one lowercase letter No whitespace characters At least one uppercase letter At least one special character Let us create a complete password validation program that checks all these conditions systematically. Complete Password Validation Program using System; using System.Linq; class PasswordValidator { public static bool IsValidPassword(string passwd) { ...

Read More
Showing 7571–7580 of 21,090 articles
« Prev 1 756 757 758 759 760 2109 Next »
Advertisements