Karthikeya Boyini has Published 2383 Articles

C# Program to check if a number is Positive, Negative, Odd, Even, Zero

karthikeya Boyini

karthikeya Boyini

Updated on 22-Jun-2020 12:08:17

2K+ Views

Check for the following conditions −For odd and even, check for the remainder when the number is divided by 2 −// checking for odd/ even if(n % 2 == 0) {    Console.WriteLine("Even"); } else {    Console.WriteLine("Odd"); }For positive, negative and checking whether a number is 0 or not ... Read More

How can we check the current MySQL transaction isolation level?

karthikeya Boyini

karthikeya Boyini

Updated on 22-Jun-2020 11:43:36

3K+ Views

By executing SELECT @@TX_ISOLATION command we can check the current MySQL transaction isolation level.Examplemysql> SELECT @@TX_ISOLATION; +-----------------+ | @@TX_ISOLATION  | +-----------------+ | REPEATABLE-READ | +-----------------+ 1 row in set (0.00 sec)

Flow control in try catch finally in C#

karthikeya Boyini

karthikeya Boyini

Updated on 22-Jun-2020 10:58:29

513 Views

The flow control in try, catch, and finally can be understood using the following example. Here, we are dividing two numbers −Example Live Demousing System; namespace ErrorHandlingApplication {    class DivNumbers {       int result;       DivNumbers() {          result = 0;   ... Read More

How to write "Hello World" in C#?

karthikeya Boyini

karthikeya Boyini

Updated on 22-Jun-2020 10:56:46

397 Views

To print “Hello World” in C#, use the Console.WriteLine.Let us see a basic C# program to display a text −Example Live Demousing System; using System.Collections.Generic; using System.Text; namespace Program {    class MyApplication {       static void Main(string[] args) {          Console.WriteLine("Hello World");     ... Read More

Sort an array in descending order using C#

karthikeya Boyini

karthikeya Boyini

Updated on 22-Jun-2020 10:25:12

335 Views

Declare an array and initialize −int[] arr = new int[] {    87,    23,    65,    29,    67 };To sort, use the Sort() method and CompareTo() to compare and display in decreasing order −Array.Sort < int > (arr, new Comparison < int > ((val1, val2) => val2.CompareTo(val1)));Let ... Read More

Date format validation using C# Regex

karthikeya Boyini

karthikeya Boyini

Updated on 22-Jun-2020 10:23:28

13K+ 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.Example Live Demousing System; using System.Globalization; namespace Demo {    class Program {     ... Read More

C# program to merge two sorted arrays into one

karthikeya Boyini

karthikeya Boyini

Updated on 22-Jun-2020 10:22:04

1K+ 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 ... Read More

What is unboxing in C#?

karthikeya Boyini

karthikeya Boyini

Updated on 22-Jun-2020 10:19:54

151 Views

Boxing is implicit and unboxing is explicit. Unboxing is the explicit conversion of the reference type created by boxing, back to a value type.Let us see an example of variable and object in C# −// int int x = 30; // Boxing object obj = x; // Un ... Read More

Singleton Class in C#

karthikeya Boyini

karthikeya Boyini

Updated on 22-Jun-2020 10:17:21

3K+ Views

Singleton Class allow for single allocations and instances of data. It has normal methods and you can call it using an instance.To prevent multiple instances of the class, the private constructor is used.Let us see an example −public class Singleton {    static Singleton b = null;    private Singleton() ... Read More

Thread-based parallelism in C#

karthikeya Boyini

karthikeya Boyini

Updated on 22-Jun-2020 10:15:20

874 Views

In C#, Task parallelism divide tasks. The tasks are then allocated to separate threads for processing. In .NET, you have the following mechanisms to run code in parallel: Thread, ThreadPool, and Task. For parallelism, use tasks in C# instead of Threads.A task will not create its own OS thread, whereas ... Read More

Advertisements