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
Programming Articles
Page 33 of 2547
Check the HybridDictionary for a specific key in C#
The HybridDictionary class in C# provides the Contains() method to check whether a specific key exists in the collection. This method returns true if the key is found, otherwise false. HybridDictionary is part of the System.Collections.Specialized namespace and automatically switches between a ListDictionary and Hashtable based on the number of entries for optimal performance. Syntax Following is the syntax for checking if a key exists in HybridDictionary − public virtual bool Contains(object key) Parameters The Contains() method accepts the following parameter − key − The key to locate in the HybridDictionary. ...
Read MoreC# Program to Show the Use of Exists Property
The Exists method in C# is a useful method that checks whether any element in a List matches a given condition. This method takes a predicate as an argument and returns a bool value indicating whether any element exists in the list that satisfies the specified condition. Syntax Following is the syntax for the Exists method − public bool Exists(Predicate match) Parameters match − A Predicate delegate that defines the conditions of the elements to search for. Return Value Returns true if at least one element matches the specified ...
Read MoreProvide a brief overview of the C# and .NET ecosystem
C# is an object-oriented, type-safe and general-purpose programming language, which focuses on making the programmers productive. It tries to achieve this productivity through expressiveness, simplicity and a focus on performance. It works on different platforms such as Windows, Mac, and Linux. The .NET ecosystem provides the foundation for C# development, offering a comprehensive runtime environment, extensive libraries, and tools for building various types of applications from desktop to web and mobile solutions. Type-Safety C# is a statically typed language. That means the types are verified when you compile a program. This eliminates a large set of errors ...
Read MoreTimeSpan.FromHours() Method in C#
The TimeSpan.FromHours() method in C# is used to create a TimeSpan object that represents a specified number of hours. This static method is accurate to the nearest millisecond and provides a convenient way to create time spans based on hour values. Syntax Following is the syntax for the TimeSpan.FromHours() method − public static TimeSpan FromHours(double value); Parameters value − A double that represents the number of hours. The value can be positive or negative and is accurate to the nearest millisecond. Return Value This method returns a ...
Read MoreGet the number of elements contained in SortedList in C#
The Count property in C# is used to get the number of elements contained in a SortedList. This property returns an integer representing the total count of key-value pairs stored in the collection. Syntax Following is the syntax for using the Count property − int count = sortedList.Count; Parameters The Count property does not take any parameters. It is a read-only property that returns the current number of elements. Return Value The Count property returns an int value representing the number of key-value pairs in the SortedList. Using Count Property ...
Read MoreWhat is use of fluent Validation in C# and how to use in C#?
FluentValidation is a powerful .NET library for building strongly-typed validation rules using a fluent interface and lambda expressions. It helps separate validation logic from your domain models, making your code cleaner and more maintainable by centralizing validation rules in dedicated validator classes. The library provides an intuitive way to define complex validation rules with built-in validators, custom validation methods, and detailed error messaging. It's particularly useful in web applications, APIs, and any scenario where robust input validation is required. Installation To use FluentValidation in your project, install the NuGet package − Syntax ...
Read MoreWhat is the usage of ref, out, and in keywords in C#?
In C#, method parameters can be passed using different modifiers that control how arguments are handled. The ref, out, and in keywords allow you to pass parameters by reference rather than by value, each serving different purposes and having specific rules. By default, C# passes arguments by value, meaning a copy of the value is created. Changes made inside the method don't affect the original variable. Default Parameter Passing (By Value) Value Types When passing value types, a copy is made and modifications inside the method don't affect the original variable − using System; ...
Read MoreTimeSpan.Subtract() Method in C#
The TimeSpan.Subtract() method in C# returns a new TimeSpan object whose value is the difference between the current instance and the specified TimeSpan object. This method is useful for calculating time differences in applications dealing with durations and intervals. Syntax Following is the syntax for the TimeSpan.Subtract() method − public TimeSpan Subtract(TimeSpan span); Parameters span − The TimeSpan object to subtract from the current instance. Return Value Returns a new TimeSpan object that represents the time interval difference. If the subtracted value is greater than the current ...
Read MoreCheck whether a Hashtable contains a specific key or not in C#
The Hashtable class in C# provides the Contains() method to check whether a specific key exists in the collection. This method returns true if the key is found, and false otherwise. Syntax Following is the syntax for checking if a Hashtable contains a specific key − bool result = hashtable.Contains(key); Parameters key − The key to search for in the Hashtable. This parameter is of type Object. Return Value The Contains() method returns a bool value − true if the Hashtable contains the specified ...
Read MoreListDictionary Class in C#
The ListDictionary class in C# implements the IDictionary interface using a singly linked list. It is optimized for small collections and is recommended for collections that typically contain fewer than 10 items. For larger collections, it's better to use Hashtable or Dictionary for better performance. Syntax Following is the syntax for creating a ListDictionary − ListDictionary dict = new ListDictionary(); dict.Add(key, value); Key Properties Property Description Count Gets the number of key/value pairs contained in the ListDictionary. IsFixedSize Gets a value indicating whether the ...
Read More