karthikeya Boyini

karthikeya Boyini

1,421 Articles Published

Articles by karthikeya Boyini

Page 49 of 143

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 880 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

C# program to copy a range of bytes from one array to another

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

Use the Buffer.BlockCopy method to copy a range of bytes from one array to another −Set a byte array −byte[] b1 = new byte[] {22, 49}; byte[] b2 = new byte[5];Copy bytes from one array to another −Buffer.BlockCopy(b1, 0, b2, 0, 2);The following is the complete code −Exampleusing System; class Demo {    static void Main(){       // byte arrays       byte[] b1 = new byte[] {22, 49};       byte[] b2 = new byte[5];       // copying bytes from one to another       Buffer.BlockCopy(b1, 0, b2, 0, 2);     ...

Read More

'this' keyword in C#

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

The “this” keyword in C# is used to refer to the current instance of the class. It is also used to differentiate between the method parameters and class fields if they both have the same name.Another usage of “this” keyword is to call another constructor from a constructor in the same class.Here, for an example, we are showing a record of Students i.e: id, Name, Age, and Subject. To refer to the fields of the current class, we have used the “this” keyword in C# −public Student(int id, String name, int age, String subject) {    this.id = id;   ...

Read More
Showing 481–490 of 1,421 articles
« Prev 1 47 48 49 50 51 143 Next »
Advertisements