karthikeya Boyini

karthikeya Boyini

1,421 Articles Published

Articles by karthikeya Boyini

Page 50 of 143

Date format validation using C# Regex

karthikeya Boyini
karthikeya Boyini
Updated on 11-Mar-2026 16K+ Views

Use the DateTime.TryParseExact method in C# for Date Format validation.They method converts the specified string representation of a date and time to its DateTime equivalent. It checks whether the entered date format is correct or not.Exampleusing System; using System.Globalization; namespace Demo {    class Program {       static void Main(string[] args) {          DateTime d;          bool chValidity = DateTime.TryParseExact(          "08/14/2018",          "MM/dd/yyyy",          CultureInfo.InvariantCulture,          DateTimeStyles.None,          out d);          Console.WriteLine(chValidity);       }    } }OutputTrue

Read More

C# Program to convert integer array to string array

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

Use the ConvertAll method to convert integer array to string array.Set an integer array −int[] intArray = new int[5]; // Integer array with 5 elements intArray[0] = 15; intArray[1] = 30; intArray[2] = 44; intArray[3] = 50; intArray[4] = 66;Now use Array.ConvertAll() method to convert integer array to string array −Array.ConvertAll(intArray, ele => ele.ToString());Let us see the complete code −Exampleusing System; using System.Text; public class Demo {    public static void Main() {       int[] intArray = new int[5];       // Integer array with 5 elements       intArray[0] = 15;       intArray[1] = 30;       intArray[2] = 44;       intArray[3] = 50;       intArray[4] = 66;       string[] strArray = Array.ConvertAll(intArray, ele => ele.ToString());       Console.WriteLine(string.Join("|", strArray));    } }Output15|30|44|50|66

Read More

Abstract Classes in C#

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

An abstract class in C# includes abstract and non-abstract methods. A class is declared abstract to be an abstract class. You cannot instantiate an abstract class.Let us see an example, wherein we have an abstract class Vehicle and abstract method display()−public abstract class Vehicle {    public abstract void display(); } The abstract class has derived classes: Bus, Car, and  Motorcycle. The following is an implementation of the Bus derived class −public class Bus : Vehicle {    public override void display() {       Console.WriteLine("Bus");    } } ExampleLet us see the complete example of abstract classes in C# −using ...

Read More

C# program to merge two sorted arrays into one

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

Set two arrays that you wish to merge −int[] arr1 = new int[5] {    5,    15,    25,    30,    47 }; int[] arr2 = new int[5] {    55,    60,    76,    83,    95 };Now take a third array that would merge both the above arrays −int[] merged = new int[10];The following is the code that merges two arrays into the third array in C# −Exampleusing System; using System.Collections.Generic; class Program {    static void Main() {       int i = 0;       int j = 0; ...

Read More

Show Bootstrap class

karthikeya Boyini
karthikeya Boyini
Updated on 11-Mar-2026 738 Views

To show a Bootstrap class, use the .show class. You can try to run the following code to make a class visibleExample           Bootstrap Example                                                       This class is visible.                                 This is an example for hide class. This will be hidden.                    

Read More

Clear a list in C#

karthikeya Boyini
karthikeya Boyini
Updated on 11-Mar-2026 493 Views

Firstly, set a list −List myList = new List(); myList.Add(45); myList.Add(77);Now, to clear the above list, use Clear() −myList.Clear();Here is the complete code −Exampleusing System; using System.Collections.Generic; public class Demo {    public static void Main() {       List myList = new List();       myList.Add(45);       myList.Add(77);       Console.WriteLine("Elements: "+myList.Count);       myList.Clear();       Console.WriteLine("Elements after using clear: "+myList.Count);    } }OutputElements: 2 Elements after using clear: 0

Read More

How to write the first program in C#?

karthikeya Boyini
karthikeya Boyini
Updated on 11-Mar-2026 624 Views

The following is the first program in C# programming −Exampleusing System; namespace MyHelloWorldApplication {    class MyDemoClass {       static void Main(string[] args) {          // display text          Console.WriteLine("Hello World");          // display another text          Console.WriteLine("Welcome!");          Console.ReadKey();       }    } }OutputHello World Welcome!Let us see now what all it includes.using System; - the using keyword is used to include the System namespace in the program.namespace declaration - A namespace is a collection ...

Read More

Flow control in try catch finally in C#

karthikeya Boyini
karthikeya Boyini
Updated on 11-Mar-2026 771 Views

The flow control in try, catch, and finally can be understood using the following example. Here, we are dividing two numbers −Exampleusing System; namespace ErrorHandlingApplication {    class DivNumbers {       int result;       DivNumbers() {          result = 0;       }       public void division(int num1, int num2) {          try {             result = num1 / num2;          } catch (DivideByZeroException e) {             Console.WriteLine("Exception caught: {0}", e);     ...

Read More

C# program to find the index of an element in a List

karthikeya Boyini
karthikeya Boyini
Updated on 11-Mar-2026 1K+ Views

Set a list and add elements −List val = new List(); // integer elements val.Add(35); val.Add(55); val.Add(68);Let’s say now we need to find the index of element 68. For that, use the IndexOf() method −int index = val.IndexOf(68);Here is the complete code −Exampleusing System; using System.Collections.Generic; public class Demo {    public static void Main() {       List val = new List();       // integer elements       val.Add(35);       val.Add(55);       val.Add(68);       // finding the index of element 68       int index = val.IndexOf(68);       Console.WriteLine(index);    } }Output2

Read More

How to declare and initialize a dictionary in C#?

karthikeya Boyini
karthikeya Boyini
Updated on 11-Mar-2026 1K+ Views

Dictionary is a collection of keys and values in C#. Dictionary is included in the System.Collection.Generics namespace.To declare and initialize a Dictionary −IDictionary d = new Dictionary();Above, types of key and value are set while declaring a dictionary object. An int is a type of key and string is a type of value. Both will get stored in a dictionary object named d.Let us now see an example −Exampleusing System; using System.Collections.Generic; public class Demo {    public static void Main() {       IDictionary d = new Dictionary();       d.Add(1, 97);       d.Add(2, ...

Read More
Showing 491–500 of 1,421 articles
« Prev 1 48 49 50 51 52 143 Next »
Advertisements