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
Server Side Programming Articles
Page 869 of 2109
Int64.GetTypeCode Method in C# with Examples
The Int64.GetTypeCode() method in C# is used to return the TypeCode for value type Int64. This method is inherited from the IConvertible interface and returns TypeCode.Int64 for all 64-bit signed integer values. Syntax Following is the syntax − public TypeCode GetTypeCode(); Return Value This method returns TypeCode.Int64, which is the enumerated constant representing the Int64 type. Using GetTypeCode() with Different Values Example Let us see an example to implement the Int64.GetTypeCode() method − using System; public class Demo { public static void Main() { ...
Read MoreMathF.Abs() Method in C# with Examples
The MathF.Abs() method in C# is used to return the absolute value of a float number. The absolute value represents the non-negative value of a number without regard to its sign. For example, the absolute value of both -5.5f and 5.5f is 5.5f. This method is part of the System namespace and is specifically designed for float operations, providing better performance than the generic Math.Abs() method when working with single-precision floating-point numbers. Syntax Following is the syntax for the MathF.Abs() method − public static float Abs(float val); Parameters val − A ...
Read MoreChar.IsPunctuation() Method in C#
The Char.IsPunctuation() method in C# determines whether a specified Unicode character is categorized as a punctuation mark. This method is useful for text processing, input validation, and character analysis tasks. Syntax Following is the syntax − public static bool IsPunctuation(char ch); Parameters ch − The Unicode character to evaluate. Return Value Returns true if the character is a punctuation mark; otherwise, false. Character Classification Punctuation ! ? . , ; : " ' ...
Read MoreDateTime.Compare() Method in C#
The DateTime.Compare() method in C# is used for comparison of two DateTime instances. It returns an integer value indicating the relationship between the two dates − 0 − If date1 is later than date2 Syntax Following is the syntax for DateTime.Compare() method − public static int Compare(DateTime d1, DateTime d2); Parameters d1 − The first DateTime instance to compare d2 − The second DateTime instance to compare Return Value The method returns an integer value − Negative integer − If d1 is earlier than ...
Read MoreC# Program to Convert Integer to String
To convert an integer to string in C#, you can use several methods. The most common approach is the ToString() method, which provides a simple and direct way to convert any integer value to its string representation. Syntax Following is the syntax for using ToString() method − string result = number.ToString(); Alternative syntax using Convert.ToString() method − string result = Convert.ToString(number); Using ToString() Method The ToString() method is called on the integer variable to convert it to a string − using System; class Program { ...
Read MoreHow to find the index of an item in a C# list in a single step?
To find the index of an item in a C# list in a single step, you can use several built-in methods. The most common approaches are IndexOf() for exact matches and FindIndex() for condition-based searches. Syntax For exact item matching − int index = list.IndexOf(item); For condition-based searching − int index = list.FindIndex(predicate); Using IndexOf() for Exact Matches The IndexOf() method returns the zero-based index of the first occurrence of the specified item − using System; using System.Collections.Generic; public class Program { public ...
Read MoreC# Program to check if a number is prime or not
A prime number is a natural number greater than 1 that has no positive divisors other than 1 and itself. To check if a number is prime in C#, we need to verify that it has exactly two divisors. Algorithm To determine if a number is prime, we use a for loop to check all numbers from 1 to the given number. We count how many divisors exist by checking if the remainder is zero when dividing the number by each potential divisor − for (int i = 1; i
Read MoreHow to find the first character of a string in C#?
To get the first character of a string in C#, you can use several approaches. The most common methods are using string indexing, the Substring() method, or the First() LINQ method. Syntax Following are the different syntaxes to get the first character − char firstChar = str[0]; string firstChar = str.Substring(0, 1); char firstChar = str.First(); Using String Indexing The simplest way to get the first character is using string indexing with [0]. This returns a char type − using System; public class Demo ...
Read MoreHow to append a second list to an existing list in C#?
Use the AddRange() method to append a second list to an existing list in C#. The AddRange() method adds all elements from one collection to the end of another list, effectively combining two lists into one. Syntax Following is the syntax for using AddRange() method − list1.AddRange(list2); Parameters collection − The collection whose elements should be added to the end of the List. The collection itself cannot be null, but it can contain elements that are null. Using AddRange() Method The AddRange() method modifies the original list by adding ...
Read MoreHow to read inputs as integers in C#?
To read inputs as integers in C#, you need to first read the input as a string using Console.ReadLine() and then convert it to an integer using methods like Convert.ToInt32() or int.Parse(). The process involves two steps: reading the user input as a string and converting it to an integer data type for mathematical operations. Syntax Following is the basic syntax for reading integer input − string input = Console.ReadLine(); int number = Convert.ToInt32(input); You can also use int.Parse() method − int number = int.Parse(Console.ReadLine()); Using Convert.ToInt32() Method ...
Read More