Ankith Reddy

Ankith Reddy

730 Articles Published

Articles by Ankith Reddy

Page 13 of 73

Write a C# program to find GCD and LCM?

Ankith Reddy
Ankith Reddy
Updated on 11-Mar-2026 1K+ Views

GCD (Greatest Common Divisor)GCD is the largest positive integer that divides each of the integers.LCM (Least Common Multiple)LCM of two numbers is the smallest integer divisible by both the numbers.The following is an example to calculate the GCD and LCM. Here, we are calculating the LCM and GCD of 10 and 16 −Exampleusing System; using System.Collections.Generic; using System.Linq; using System.Text; namespace Demo {    class Program {       static void Main(string[] args) {          int val1, val2, n1, n2, x;          int resLCM, resGCD;          val1 = ...

Read More

Remove Leading Zeros from a String in C#

Ankith Reddy
Ankith Reddy
Updated on 11-Mar-2026 14K+ Views

Let’s say the following is our string with leading zeros.String str ="000234";Use the TrimStart() method and set the 0 to remove it.TrimStart(new Char[] { '0' } )The following is the complete code to remove leading zeros.Exampleusing System; class Program {    static void Main() {       String str ="000234".TrimStart(new Char[] { '0' } );       Console.WriteLine(str);    } }Output234

Read More

Bootstrap Collapsible button

Ankith Reddy
Ankith Reddy
Updated on 11-Mar-2026 570 Views

The collapsible button is used in Bootstrap to create a collapsible that can be shown or hidden on click.You can try to run the following code to create a collapsible button:Example           Bootstrap Example                                          Contact Us          Click for more info...          More                       You can also contact us on 9199****** for more information on our products.                    

Read More

C# Program to write a number in hexadecimal format

Ankith Reddy
Ankith Reddy
Updated on 11-Mar-2026 613 Views

Let’s say the following is the number −int a = 12250;You can work around the following ways to get a number in hexadecimal format −{0:x} {0:x8} {0:X} {0:X8}Here is the code −Exampleusing System; class Demo {    static void Main() {       int a = 12250;       Console.WriteLine("{0:x}", a);       Console.WriteLine("{0:x8}", a);       Console.WriteLine("{0:X}", a);       Console.WriteLine("{0:X8}", a);    } }Output2fda 00002fda 2FDA 00002FDA

Read More

What are the differences between constructors and destructors in C#?

Ankith Reddy
Ankith Reddy
Updated on 11-Mar-2026 581 Views

ConstructorsA class constructor is a special member function of a class that is executed whenever we create new objects of that class.A constructor has exactly the same name as that of class and it does not have any return type.Constructor has the same name as the class name −class Demo {    public Demo() {} }The following is an example −Exampleusing System; namespace LineApplication {    class Line {       private double length; // Length of a line       public Line() {          Console.WriteLine("Object is being created");     ...

Read More

Bootstrap well class

Ankith Reddy
Ankith Reddy
Updated on 11-Mar-2026 239 Views

A well is a container in that causes the content to appear sunken or an inset effect on the page. To create a well, simply wrap the content that you would like to appear in the well with a containing the class of .well.You can try to run the following code to implement well class in Bootstrap −Example           Bootstrap Example                                 This is demo text!    

Read More

How to initialize a string to an empty string in C#?

Ankith Reddy
Ankith Reddy
Updated on 11-Mar-2026 3K+ Views

To initialize a string to an empty list −string myStr = null;Now, use the built-in method IsNullOrEmpty() to check whether the list is empty or not −if (string.IsNullOrEmpty(myStr)) {    Console.WriteLine("String is empty or null!"); }Let us see the complete code −Exampleusing System; namespace Demo {    class Program {       static void Main(string[] args) {          string myStr = null;          if (string.IsNullOrEmpty(myStr)) {             Console.WriteLine("String is empty or null!");          }          Console.ReadKey();       } ...

Read More

C# Program to generate random lowercase letter

Ankith Reddy
Ankith Reddy
Updated on 11-Mar-2026 2K+ Views

Firstly, set Random class −Random random = new Random();Set a range under the Next() method. This displays a letter between 0 and 26.int a = random.Next(0, 26);Here is the complete code −Exampleusing System; using System.IO; using System.Linq; class Demo {    static void Main() {       Random random = new Random();       // random lowercase letter       int a = random.Next(0, 26);       char ch = (char)('a' + a);       Console.WriteLine(ch);    } }Outputt

Read More

Create a green color alert box that indicates a positive action in Bootstrap

Ankith Reddy
Ankith Reddy
Updated on 11-Mar-2026 1K+ Views

To create a green color alert box indicating a positive action, use the alert-success class.To implement an alert-success class, you need to try to run the following code −Example           Bootstrap Example                                          Indicates a positive action!          

Read More

Func generic type in C#

Ankith Reddy
Ankith Reddy
Updated on 11-Mar-2026 953 Views

The Func generic type store anonymous methods and is a parameterized type.In the below example, we have 4 func type instance −The first type receives int and returns stringFunc one = (p) => string.Format("{0}", p);The second type receives bool & long and returns stringFunc two = (q, p) =>string.Format("{0} and {1}", q, p);The third type receives bool & int and returns stringFunc three = (q, p) => string.Format("{0} and {1}", q, p);The fourth type receives decimal and returns stringFunc four = (p) =>string.Format("{0}", p);Let us see how to display them −Exampleusing System; using System.IO; namespace Demo {    class ...

Read More
Showing 121–130 of 730 articles
« Prev 1 11 12 13 14 15 73 Next »
Advertisements