To check the status of the current thread in C#, use the IsAlive property.Firstly, use the currentThread property to display information about a thread −Thread thread = Thread.CurrentThread;Now use the thread.IsAlive property to check the status of the thread −thread.IsAliveExampleLet us see the complete code to check the status of current thread in C#.Live Demousing System; using System.Threading; namespace Demo { class MyClass { static void Main(string[] args) { Thread thread = Thread.CurrentThread; thread.Name = "My New Thread"; Console.WriteLine("Thread Status = {0}", thread.IsAlive); Console.ReadKey(); } } }OutputThread Status = True
Bubble sort is a simple sorting algorithm. This sorting algorithm is a comparison-based algorithm in which each pair of adjacent elements is compared and the elements are swapped if they are not in order.Let’s say our int has 5 elements −int[] arr = { 78, 55, 45, 98, 13 };Now, let us perform Bubble Sort.Start with the first two elements 78 and 55. 55 is smaller than 78, so swap both of them. Now the list is −55, 78, 45, 98, 13Now 45 is less than 78, so swap it.55, 45, 78, 98, 3Now 98 is greater than 78, so ... Read More
Multiple Inheritance isn’t supported in C#. To implement multiple inheritances, use Interfaces.Here is our interface PaintCost in class Shape −public interface PaintCost { int getCost(int area); }The shape is our base class whereas Rectangle is the derived class −class Rectangle : Shape, PaintCost { public int getArea() { return (width * height); } public int getCost(int area) { return area * 80; } }Let us now see the complete code to implement Interfaces for multiple inheritances in C# −Using System; namespace MyInheritance { class Shape { ... Read More
More than one class is inherited from the base class in Hierarchical Inheritance.In the example, our base class is Father −class Father { public void display() { Console.WriteLine("Display..."); } }It has Son and Daughter as the derived class. Let us how to add a derived class in Inheritance −class Son : Father { public void displayOne() { Console.WriteLine("Display One"); } }ExampleThe following the complete example of implementing Hierarchical Inheritance in C# −using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace Inheritance { class Test { static ... Read More
Use the contains() method in C# to check if a substring is in a given string.Let us say the string is −UnitedWithin the string, you need to find the substring “Uni”. For that, use the contains method and use it like the following code snippet −res = str1.Contains(str2);ExampleYou can try to run the following code to find a substring in a string.Live Demousing System; public class Demo { public static void Main() { string str1 = "United", str2 = "Uni"; bool res; res = str1.Contains(str2); if (res) ... Read More
A pangram has all the 26 letters of an alphabet.Below, we have entered a string, and will check whether it is a pangram or not −string str = "The quick brown fox jumps over the lazy dog";Now, check using the ToLower(), isLetter() and Count() functions that the string has all the 26 letters of not since pangram has all the 26 letters of an alphabet.ExampleYou can try to run the following code to check whether a string is pangram or not.Live Demousing System; using System.Collections.Generic; using System.Linq; using System.Text.RegularExpressions; namespace Demo { public class Program { ... Read More
To check whether the matrices are identical or not, you need to first check whether the matrixes can be compared or not, since for comparison at least the dimensions of the two matrices should be the same.if (row1 != row2 && col1 != col2) { Console.Write("Matrices can't be compared:"); }Now, under else condition check for whether the metrics are identical or not. We have also set a flag here −if (row1 != row2 && col1 != col2) { Console.Write("Matrices can't be compared:"); } else { Console.Write("Comparison of Matrices: "); for (i = 0; i < row1; ... Read More
The following are some of the Math Functions in JavaScript −S.NoMethod & Description 1abs()Returns the absolute value of a number.2acos()Returns the arccosine (in radians) of a number.3asin()Returns the arcsine (in radians) of a number.4atan()Returns the arctangent (in radians) of a number.5atan2()Returns the arctangent of the quotient of its arguments.6ceil()Returns the smallest integer greater than or equal to a number.ExampleLet’s see an example of abs() Math function in JavaScript. The Math() function returns the absolute value of a number − JavaScript Math abs() Method var ... Read More
The async and await keyword is used in C# for asynchronous programming.An application with a GUI, check the content of the queue and if an unprocessed task is there, it takes it out and processes it first. The code executes synchronously and the unprocessed task is completed first. The application will show stop responding to messages if the processing takes more time than expected.Let us see what is discussed above −private void OnRequestDownload(object sender, RoutedEventArgs e) { var req = HttpWebRequest.Create(_requestedUri); var res = req.GetResponse(); }To solve the above issue, use the async and await keywords −private async ... Read More
BoxingBoxing is the implicit conversion of a value type to a reference type.UnboxingUnboxing is the explicit conversion of the reference type created by boxing, back to a value type.ExampleLet us see an example code snippet −// int int myVal = 12; // Boxing object myBoxed = myVal; // Unboxing int myUnBoxed = (int) myBoxed;Let us see another example that shows an array list in C# −int a = 5; ArrayList arr = new ArrayList(); // Boxing arr.Add(a); // UnBoxing int b = (int)arr[0];
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP