George John

George John

789 Articles Published

Articles by George John

Page 7 of 79

How to convert a string into int in C#?

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

Converting a string to an integer in C# is a common task that can be accomplished using several methods. The most straightforward approach is using Int32.Parse() method, which converts the string representation of a number to its 32-bit signed integer equivalent. Syntax Following is the syntax for using Int32.Parse() method − int result = Int32.Parse(stringValue); Following is the syntax for using Convert.ToInt32() method − int result = Convert.ToInt32(stringValue); Following is the syntax for using int.TryParse() method − bool success = int.TryParse(stringValue, out int result); Using Int32.Parse() ...

Read More

Networking in C#

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

The .NET Framework provides a layered, extensible, and managed implementation of networking services that you can easily integrate into your applications. The System.Net namespace contains classes for network communication, web requests, DNS operations, and secure connections. Syntax To use networking classes, include the System.Net namespace − using System.Net; Creating a URI and web request − Uri uri = new Uri("http://www.example.com/"); WebRequest request = WebRequest.Create(uri); Using Uri Class The Uri class in C# provides object representation of a uniform resource identifier (URI). It helps parse and manipulate web addresses − ...

Read More

C# Program to Add Two TimeSpan

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

The TimeSpan structure in C# represents a time interval and provides methods to perform arithmetic operations. You can add two TimeSpan objects using the Add() method or the + operator to get the combined duration. Syntax Following is the syntax for adding two TimeSpan objects using the Add() method − TimeSpan result = timespan1.Add(timespan2); You can also use the + operator for addition − TimeSpan result = timespan1 + timespan2; Using the Add() Method The Add() method returns a new TimeSpan that represents the sum of two time intervals ...

Read More

Stopwatch class in C#

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

The Stopwatch class in C# is used to measure elapsed time with high precision. It provides accurate timing measurements for performance monitoring and benchmarking applications. The class is found in the System.Diagnostics namespace. Syntax Following is the syntax for creating and starting a Stopwatch − Stopwatch stopwatch = new Stopwatch(); stopwatch.Start(); Alternatively, you can create and start in one line − Stopwatch stopwatch = Stopwatch.StartNew(); Key Properties and Methods Property/Method Description Start() Starts measuring elapsed time Stop() Stops measuring elapsed ...

Read More

Get first three letters from every string in C#

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

In C#, you can extract the first three letters from every string using the Substring() method combined with LINQ operations. This is useful for creating abbreviations, prefixes, or shortened versions of strings in a collection. Syntax Following is the syntax for getting a substring from a string − string.Substring(startIndex, length) Following is the syntax for applying substring to a collection using LINQ − collection.Select(str => str.Substring(0, 3)) Using Substring with LINQ Select The most common approach is to use the Substring() method with LINQ's Select() method to transform each ...

Read More

How do you find the length of an array in C#?

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

To find the length of an array in C#, use the Length property (not a method). The Length property returns the total number of elements in the array as an integer value. Syntax Following is the syntax for using the Length property − int length = arrayName.Length; Parameters arrayName − The array whose length you want to find Return Value The Length property returns an int value representing the total number of elements in the array. Example Let us see an example − using System; ...

Read More

Ulong type in C#

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

The ulong type in C# is a 64-bit unsigned integer that represents the System.UInt64 structure. It can store values from 0 to 18, 446, 744, 073, 709, 551, 615, making it ideal for storing large positive numbers without sign considerations. The ulong keyword is an alias for System.UInt64 and is part of C#'s built-in value types. Since it's unsigned, it cannot store negative values but has twice the positive range compared to long. Syntax Following is the syntax for declaring a ulong variable − ulong variableName = value; You can also use the ...

Read More

KeyValuePair in C#

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

The KeyValuePair struct in C# stores a pair of values in a single object, where one value acts as the key and the other as the value. It is commonly used in collections like List and as the element type in dictionaries. KeyValuePair is particularly useful when you need to associate two related pieces of data together without creating a custom class or when working with dictionary enumerations. Syntax Following is the syntax for creating a KeyValuePair − KeyValuePair pair = new KeyValuePair(key, value); Following is the syntax for accessing key and value ...

Read More

What is the difference between overriding and shadowing in C#?

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

In C#, overriding and shadowing (also known as method hiding) are two different mechanisms for modifying inherited behavior. Overriding uses the virtual/override keywords to provide specific implementations of base class methods, while shadowing uses the new keyword to hide base class members entirely. Syntax Following is the syntax for method overriding − // Base class public virtual void MethodName() { } // Derived class public override void MethodName() { } Following is the syntax for method shadowing/hiding − // Base class public void MethodName() { } // Derived class public ...

Read More

C# orderby Keyword

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

The orderby keyword in C# is used to sort data in LINQ queries. It allows you to sort collections in either ascending or descending order based on one or more criteria. Syntax Following is the syntax for using orderby in LINQ queries − from element in collection orderby element ascending select element; For descending order − from element in collection orderby element descending select element; Multiple sorting criteria can be applied using commas − from element in collection orderby element.Property1, element.Property2 descending select element; Using orderby ...

Read More
Showing 61–70 of 789 articles
« Prev 1 5 6 7 8 9 79 Next »
Advertisements