karthikeya Boyini

karthikeya Boyini

1,421 Articles Published

Articles by karthikeya Boyini

Page 48 of 143

Write a C# program to calculate a factorial using recursion

karthikeya Boyini
karthikeya Boyini
Updated on 11-Mar-2026 3K+ Views

Factorial of a number is what we are finding using a recursive function checkFact () in the below example −If the value is 1, it returns 1 since Factorial is 1 −if (n == 1) return 1;If not, then the recursive function will be called for the following iterations if you want the value of 5!Interation1: 5 * checkFact (5 - 1); Interation2: 4 * checkFact (4 - 1); Interation3: 3 * checkFact (3 - 1); Interation4: 4 * checkFact (2 - 1);To calculate a factorial using recursion, you can try to run the following code which ...

Read More

C# program to return an array from methods

karthikeya Boyini
karthikeya Boyini
Updated on 11-Mar-2026 12K+ Views

Call a method under Join method to join words −string.Join(" ", display())Now set a string array −string[] str = new string[5];Add individual elements −str[0] = "My"; str[1] = "name"; str[2] = "is"; str[3] = "Brad"; str[4] = "Pitt";And return the same string array from method −return str;The following is the complete code −Exampleusing System; public class Demo {    public static void Main() {       Console.WriteLine(string.Join(" ", display()));    }    static string[] display() {       string[] str = new string[5];       // string array elements       str[0] = "My";       str[1] = "name";       str[2] = "is";       str[3] = "Brad";       str[4] = "Pitt";       return str;    } }OutputMy name is Brad Pitt

Read More

C# program to get the last element from an array

karthikeya Boyini
karthikeya Boyini
Updated on 11-Mar-2026 3K+ Views

Firstly, set an array −string[] str = new string[]{    "Java",    "HTML",    "jQuery",    "JavaScript",    "Bootstrap" };To get the value of the last element, get the length and display the following value −str[str.Length - 1]The above returns the last element.Here is the complete code −Exampleusing System; public class Demo {    public static void Main() {       string[] str = new string[] {          "Java",          "HTML",          "jQuery",          "JavaScript",          "Bootstrap"       };       Console.WriteLine("Array...");       foreach(string res in str) {          Console.WriteLine(res);       }       Console.WriteLine("Last element: "+str[str.Length - 1]);    } }OutputArray... Java HTML jQuery JavaScript Bootstrap Last element: Bootstrap

Read More

How to find the Sum of two Binary Numbers using C#?

karthikeya Boyini
karthikeya Boyini
Updated on 11-Mar-2026 2K+ Views

To find the sum of two binary numbers, firstly set them.val1 = 11110; val2 = 11100;Now call the displaySum() method, which created to display the sumL.sum = displaySum(val1, val2);We have set a new array in the method to display each bit of the binary number.long[] sum = new long[30];Now let us see the complete code to calculate the sum of binary numbers as shown in the code below −Exampleusing System; class Demo {    public static void Main(string[] args) {       long val1, val2, sum = 0;       val1 = 11110;       val2 = ...

Read More

How to use the sleep method in C#?

karthikeya Boyini
karthikeya Boyini
Updated on 11-Mar-2026 879 Views

The sleep method of the thread is used to pause the thread for a specific period.If you want to set sleep for some seconds, then use it like the following code snippet −int sleepfor = 2000; Thread.Sleep(sleepfor);You can try to run the following code to implement the sleep method of the thread −Exampleusing System; using System.Threading; namespace MyApplication {    class ThreadCreationProgram {       public static void CallToChildThread() {          Console.WriteLine("Child thread starts");          int sleepfor = 2000;          Console.WriteLine("Child Thread Paused for {0} seconds", sleepfor ...

Read More

How to check if a string is a valid keyword in C#?

karthikeya Boyini
karthikeya Boyini
Updated on 11-Mar-2026 2K+ Views

To check if a string is a valid keyword, use the IsValidIdentifier method.The IsValidIdentifier method checks whether the entered value is an identifier or not. If it’s not an identifier, then it’s a keyword in C#.Let us see an example, wherein we have set the CodeDomProvider and worked with the IsValiddentifier method −CodeDomProvider provider = CodeDomProvider.CreateProvider("C#");Let us see the complete codeLExampleusing System; using System.IO; using System.CodeDom.Compiler; namespace Program {    class Demo {       static void Main(string[] args) {              string str1 = "amit";          string str2 = "for"; ...

Read More

Add buttons in Bootstrap Navbar

karthikeya Boyini
karthikeya Boyini
Updated on 11-Mar-2026 3K+ Views

Add buttons using class .navbar-btn to elements. You can try to run the following code to add a button to the navbarExample           Bootstrap Example                                                       Example                                                                                                  Submit Button                         Navbar Button                    

Read More

How do you loop through a C# array?

karthikeya Boyini
karthikeya Boyini
Updated on 11-Mar-2026 6K+ Views

To loop through an array in C#, use any of the loops. These loops have starting and ending value set that allows you to set or check value through iterations.C# has while, do…while, for and foreach loops to loop through an array.Let us see an example of for loop in C# −Exampleusing System; namespace ArrayApplication {    class MyArray {       static void Main(string[] args) {          int [] n = new int[10];          int i, j;          for ( i = 0; i < 10; i++ ...

Read More

Singleton Class in C#

karthikeya Boyini
karthikeya Boyini
Updated on 11-Mar-2026 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() {       }   }The following is another example displaying how to display Singleton class −Exampleusing System; class Singleton {    public static readonly Singleton _obj = new Singleton();          public void Display() {       Console.WriteLine(true);    }    Singleton() {} } class Demo {    public static void Main() {       Singleton._obj.Display();    } }OutputTrue

Read More

What are destructors in C# programs?

karthikeya Boyini
karthikeya Boyini
Updated on 11-Mar-2026 2K+ Views

A destructor is a special member function of a class that is executed whenever an object of its class goes out of scope.It has exactly the same name as that of the class with a prefixed tilde (~), for example, our class name is Demo.public Demo() { // constructor    Console.WriteLine("Object is being created"); } ~Demo() { //destructor    Console.WriteLine("Object is being deleted"); }Let us see an example to learn how to work with Destructor in C#.Exampleusing System; namespace LineApplication {    class Line {       private double length; // Length of a line     ...

Read More
Showing 471–480 of 1,421 articles
« Prev 1 46 47 48 49 50 143 Next »
Advertisements