Csharp Articles

Page 164 of 196

Different Methods to find Prime Numbers in C#

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

A prime number is a natural number greater than 1 that has no positive divisors other than 1 and itself. In C#, there are several methods to check if a number is prime, each with different approaches and efficiency levels. What is a Prime Number? A prime number is divisible only by 1 and itself. For example, 2, 3, 5, 7, 11 are prime numbers. The number 1 is not considered prime, and 2 is the only even prime number. Prime vs Composite Numbers Prime Numbers ...

Read More

What is the IsReadOnly property of Hashtable class in C#?

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

The IsReadOnly property of the Hashtable class in C# returns a boolean value indicating whether the Hashtable is read-only. When a Hashtable is read-only, you cannot add, remove, or modify its elements. By default, all Hashtable instances created using the standard constructor are not read-only, meaning they allow modifications. However, you can create read-only wrappers using specific methods. Syntax Following is the syntax for accessing the IsReadOnly property − bool isReadOnly = hashtable.IsReadOnly; Return Value The IsReadOnly property returns − true if the Hashtable is read-only false if the Hashtable ...

Read More

Difference between IComparable and IComparer Interface in C#

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

The IComparable and IComparer interfaces in C# are both used for sorting and comparing objects, but they serve different purposes and are implemented in different ways. The IComparable interface allows an object to compare itself with another object of the same type. The IComparer interface provides a way to compare two objects externally, offering more flexibility for custom sorting logic. Syntax Following is the syntax for implementing IComparable − public class ClassName : IComparable { public int CompareTo(object obj) { // comparison logic ...

Read More

Differences between C and C#

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

C is a general-purpose, high-level programming language originally developed by Dennis M. Ritchie to develop the UNIX operating system at Bell Labs. C was first implemented on the DEC PDP-11 computer in 1972. C# is a simple, modern, general-purpose, object-oriented programming language developed by Microsoft within its .NET initiative led by Anders Hejlsberg. It was designed to combine the power of C++ with the simplicity of Visual Basic. While both languages share the letter "C" in their names, they represent different programming paradigms and approaches. Here are the key differences between C and C#. ...

Read More

Division Operator in C#

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

The division operator (/) in C# is used to divide one number by another. It performs mathematical division between a numerator and denominator, such as 9 / 3 = 3. The division operator is part of the arithmetic operators in C# and behaves differently depending on the data types involved. Understanding these differences is crucial for accurate calculations. Syntax Following is the syntax for the division operator − result = numerator / denominator; Integer Division When both operands are integers, C# performs integer division, which truncates the decimal part and returns only ...

Read More

Enum with Customized Value in C#

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

An enum (enumeration) in C# is used to store a set of named constants such as days of the week, months, seasons, or any fixed collection of related values. By default, enum constants start from 0 and increment by 1, but you can customize these values to match your specific requirements. Customizing enum values is useful when you need specific numeric representations, want to maintain compatibility with external systems, or need non-sequential numbering. Syntax Following is the syntax for declaring an enum with customized values − public enum EnumName { Value1 ...

Read More

Comparing dates using C#

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

Comparing dates in C# is accomplished using the DateTime structure, which provides built-in comparison operators and methods. The DateTime class allows you to compare dates using standard operators like , ==, and specialized methods like Compare(). Syntax Following is the syntax for creating DateTime objects for comparison − DateTime date1 = new DateTime(year, month, day); DateTime date2 = new DateTime(year, month, day); Following are the comparison operators and methods available − // Using comparison operators if (date1 < date2) { } if (date1 > date2) { } if (date1 == date2) { ...

Read More

Comparison between C# and .NET Framework

Arjun Thakur
Arjun Thakur
Updated on 17-Mar-2026 711 Views

C# is a programming language, while the .NET Framework is a comprehensive software development platform created by Microsoft. Understanding the relationship between these two is fundamental for .NET developers. The .NET Framework provides the Common Language Runtime (CLR), which serves as the execution environment for .NET applications. It also includes an extensive Base Class Library (BCL) that offers pre-built functionality for common programming tasks. What is C#? C# is an object-oriented programming language that runs on the .NET Framework. It was designed specifically for the .NET platform and compiles to Intermediate Language (IL) code, which the CLR ...

Read More

Difference between namespace in C# and packages in Java

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

Both C# namespaces and Java packages are used to organize code and prevent naming conflicts, but they have different features and implementations. Understanding their differences helps developers work effectively in both languages. Packages in Java Packages in Java are used to prevent naming conflicts, control access, and make searching and locating classes, interfaces, enumerations, and annotations easier. Java packages also provide access control through package-private visibility. Java Package Syntax package package_name; Example // Java equivalent concept in C# using System; namespace Company.Project.Utilities { public class Calculator { ...

Read More

Difference between Static Constructor and Instance Constructor in C#

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

In C#, constructors are special methods used to initialize objects. There are two main types: static constructors and instance constructors. Understanding their differences is crucial for proper class initialization and memory management. Static Constructor A static constructor is declared using the static modifier and is responsible for initializing static members of a class. It executes only once during the application lifetime, before any static members are accessed or any instances are created. Syntax static ClassName() { // initialize static members } Instance Constructor An instance constructor initializes instance ...

Read More
Showing 1631–1640 of 1,951 articles
« Prev 1 162 163 164 165 166 196 Next »
Advertisements