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];
A thread is defined as the execution path of a program. Each thread defines a unique flow of controlBackground ThreadsWhen the foreground threads will close, the background threads will be terminated.The property used for background thread is IsBackground that gets or sets a value indicating whether a thread is a background thread. The default value of this property would be false because the default threads created are Foreground Threads.To create a background thread −Thread bgThread = new Thread(tStart); bgThread.IsBackground = true; bgThread.Start();Foreground ThreadsForeground threads continue to run until the last foreground thread is terminated.When all the foreground threads are stopped, ... Read More
As the name suggests the Background Worker Class allows you to set a thread continuously running in the background and communicating with the main thread whenever required.BackgroundWorker makes the implementation of threads in Windows Forms. Intensive tasks need to be done on another thread so the UI does not freeze. It is necessary to post messages and update the user interface when the task is done. The following properties are used in BackgroundWorker class:Reference: Microsoft Developer Network (MSDN)S.No.Name & Description1CancellationPendingA value indicating whether the application has requested cancellation of a background operation.2CanRaiseEventsGets a value indicating whether the component can raise an ... Read More
To create a calculator program in C#, you need to use Web Forms. Under that create buttons from 1-9, addition, subtraction, multiplication, etc.Let us see the code for addition, subtraction, and multiplication. Firstly, we have declared two variables −static float x, y;Now, we will see how to set codes for calculation on individual button click: Our result textbox is tbResult since we have used Windows Form as well to display the calculator −protected void add_Click(object sender, EventArgs e) { x = Convert.ToInt32(tbResult.Text); tbResult.Text = ""; y = '+'; tbResult.Text += y; } protected void sub_Click(object sender, ... Read More
Use the BigInteger to handle big numbers in C#. The assembly to add for BigInteger is System. Numerics.In c# Big integer is found in System.Numerics.BigInteger.SyntaxThe syntax of BigInteger −[SerializableAttribute] public struct BigInteger : IFormattable, IComparable, IComparable, IEquatableLet us see an example code snippet −BigInteger num = BigInteger.Multiply(Int64.MaxValue, Int64.MaxValue);You can create BigInteger like this −BigInteger num = new BigInteger(double.MaxValue);The following are some of its constructors −S.No.Constructor & Description1BigInteger(Byte[ ])A new instance of the BigInteger structure using the values in a byte array.2BigInteger(Decimal)A new instance of the BigInteger structure using a Decimal value. 3BigInteger(Double)A new instance of ... Read More
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP