Ankith Reddy has Published 996 Articles

Reverse a Stack using C#

Ankith Reddy

Ankith Reddy

Updated on 22-Jun-2020 09:39:38

4K+ Views

Set a stack and add elements to it.Stack st = new Stack(); st.Push('P'); st.Push('Q'); st.Push('R');Now set another stack to reverse it.Stack rev = new Stack();Until the count of ths Stack is not equal to 0, use the Push and Pop method to reverse it.while (st.Count != 0) {    rev.Push(st.Pop()); ... Read More

String Template Class in C#

Ankith Reddy

Ankith Reddy

Updated on 22-Jun-2020 09:29:37

461 Views

StringTemplate class is used to parse the format string, so that it is compatible with String.Format. The StringTemplate class comes under the NString library that has extension methods. These methods makes string manipulations easy to use like.IsNullOrEmpty() IsNullOrWhiteSpace() Join() Truncate() Left() Right() Capitalize()StringTemplate.Format is better than String.Format since it is ... Read More

How to convert a list to string in C#?

Ankith Reddy

Ankith Reddy

Updated on 22-Jun-2020 09:25:18

3K+ Views

Declare a list.List < string > l = new List < string > ();Now, add elements to the list.// elements l.Add("Accessories"); l.Add("Footwear"); l.Add("Watches");Now convert it into a string.string str = string.Join(" ", l.ToArray());Let us see the final code to convert a list to string in C# −Exampleusing System; using System.Collections.Generic; ... Read More

How to check if an item exists in a C# array?

Ankith Reddy

Ankith Reddy

Updated on 22-Jun-2020 09:11:45

5K+ Views

Use the Equals method to check if an item exists in a C# array.Set string and substring −string subStr = "pqrs"; string[] str = {    "abcd",    "ijkl",    "pqrs",    "wxyz" };Now check whether the substring is part of the string or not using the Equals method.if (item.Equals(subStr)) ... Read More

How to print one dimensional array in reverse order?

Ankith Reddy

Ankith Reddy

Updated on 22-Jun-2020 09:08:24

531 Views

Firstly, declare and initialize one dimensional array.int[] arr = { 35, 12, 66, 90, 34, 2, 64 };Now, use the following to reverse −Array.Reverse(arr);The following is the complete code to reverse a one-dimensional array;Example Live Demousing System; class Demo {    static void Main() {       int[] arr ... Read More

How to find a number in a string in C#?

Ankith Reddy

Ankith Reddy

Updated on 22-Jun-2020 09:05:10

401 Views

To find a number in a string, use Regular Expressions.We have set the Regex pattern to get number from a string.Regex r = new Regex(@"\d+");Now, use Match class in C# to set the string.Match m = r.Match("Welcome! We are open 365 days in a year!");Use the Success property now to ... Read More

Lifecycle and States of a Thread in C#

Ankith Reddy

Ankith Reddy

Updated on 22-Jun-2020 08:57:53

526 Views

Threads are lightweight processes. Each thread defines a unique flow of control. The life cycle of a thread starts when an object of the System.Threading.Thread class is created and ends when the thread is terminated or completes execution.Here are the various states in the life cycle of a thread −The Unstarted ... Read More

Quickly convert Decimal to other bases in C#

Ankith Reddy

Ankith Reddy

Updated on 22-Jun-2020 08:37:39

695 Views

To quickly convert decimal to other bases, use Stacks. Let us see an example.Firstly, I have set the variable “baseNum” as 2int baseNum = 2;In the same way, if you want another base, then −// base 8 int baseNum = 8; // base 10 int baseNum = 10;After getting ... Read More

What is the use of comparison operators with MySQL subquery?

Ankith Reddy

Ankith Reddy

Updated on 22-Jun-2020 08:25:03

196 Views

The subquery can return at most one value. The value can be the result of an arithmetic expression or a column function. MySQL then compares the value that results from the subquery with the value on the other side of the comparison operator. MySQL subquery can be used before or ... Read More

How to perform Division of Exponents of Same Base using C#?

Ankith Reddy

Ankith Reddy

Updated on 22-Jun-2020 08:23:13

208 Views

Firstly, set the base −double n = 10;Now set the two exponents for division −double e1 = 10; double e2 = 8;Let us see the complete code to get the result of division of exponents of the same base.Example Live Demousing System; class Demo {    static void Main() { ... Read More

Advertisements