Csharp Articles

Page 82 of 196

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

karthikeya Boyini
karthikeya Boyini
Updated on 17-Mar-2026 720 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

How to get int value from enum in C#?

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

In C#, an enum (enumeration) is a value type that represents a group of named constants. By default, each enum value has an underlying integer value starting from 0. You can extract the integer value from an enum using type casting. Syntax Following is the syntax for casting an enum to int − int value = (int)EnumName.EnumValue; Following is the syntax for declaring an enum − public enum EnumName { Value1, Value2, Value3 } Using Default Integer Values By default, enum values are assigned integer values starting from 0 ...

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 726 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 864 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

How to write single-line comments in C#?

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

Single-line comments in C# are created using two forward slashes (//). Everything after the // on that line is treated as a comment and is ignored by the compiler. These comments are useful for explaining code, adding notes, or temporarily disabling a line of code. Syntax Following is the syntax for single-line comments in C# − // This is a single-line comment int variable = 10; // Comment at the end of a line Using Single-Line Comments for Code Documentation Example using System; namespace Demo { class ...

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

Binary search in C#

Ravi Ranjan
Ravi Ranjan
Updated on 17-Mar-2026 12K+ Views

The binary search algorithm works on the divide and conquer principle as it keeps dividing the array in half before searching. To search for an element in an array using binary search, the array must be sorted. In the sorted array, we find the middle element and compare it with the element that has to be searched, and based on the comparison, we either search in the left sub-array, right sub-array, or return the middle element. In this article, we are given a sorted array of integers, and our task is to search for the given target element ...

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
Showing 811–820 of 1,951 articles
« Prev 1 80 81 82 83 84 196 Next »
Advertisements