karthikeya Boyini

karthikeya Boyini

1,421 Articles Published

Articles by karthikeya Boyini

Page 66 of 143

What does Array.LongLength property of array class do in C#?

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

The Array.LongLength property gets a 64-bit integer that represents the total number of elements in all the dimensions of the Array.Let’s say your array of long data type is −long[,] arr1= new long[15, 35];Use the LongLength property to get an integer representing the total number of elements in all dimensions of the Array −arr1.LongLengthLet us see an example to implement the Array.LongLength property of array class −Exampleusing System; class Program {    static void Main() {       long[,] arr1= new long[15, 35];       long len1 = arr1.GetLongLength(0);       Console.WriteLine(len1);       Console.WriteLine(arr1.LongLength);    } }Output15 525

Read More

Compare two strings lexicographically in C#

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

To compare strings in C#, use the compare() method. It compares two strings and returns the following integer values −If str1 is less than str2, it returns -1. If str1 is equal to str2, it returns 0. If str1 is greater than str2, it returns 1.Set the two strings in the String.compare() method and compare them −string.Compare(string1, string2);ExampleYou can try to run the following code to compare two strings in C#.using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace Demo {    class MyApplication {       static void Main(string[] args) {          string ...

Read More

Does declaring an array create an array in C#?

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

Declaring an array does not initialize the array in the memory. When the array variable is initialized, you can assign values to the array.The following is a declaration and it will not create an array −int[] id;The following create an array of integers. The array is a reference type, so you need to use the new keyword to create an instance of the array −Int[] id = new int[5] {};Let us see an example −Exampleusing System; namespace ArrayApplication {    public class MyArray {       public static void Main(string[] args) {          int [] ...

Read More

How to iterate two Lists or Arrays with one foreach statement in C#?

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

Set two arrays.var val = new [] { 20, 40, 60}; var str = new [] { "ele1", "ele2", "ele3"};Use the zip() method to process the two arrays in parallel.var res = val.Zip(str, (n, w) => new { Number = n, Word = w });The above fetches both the arrays with int and string elements respectively.Now, use foreach to iterate the two arrays −Exampleusing System; using System.Collections.Generic; using System.Linq; public class Demo {    public static void Main() {       var val = new [] { 20, 40, 60};       var str = new [] ...

Read More

What is the use of 'new' keyword in C#?

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

Use the new keyword to create an instance of the array −int [] a = new int[5];The new operator is used to create an object or instantiate an object. Here in the example, an object is created for the class using the new −Exampleusing System; namespace CalculatorApplication {    class NumberManipulator {       public void swap(int x, int y) {          int temp;          temp = x; /* save the value of x */          x = y; /* put y into x */       ...

Read More

Bootstrap Horizontal Form

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

To create a horizontal form in Bootstrap, follow the below steps − Add a class of .form-horizontal to the parent element. Wrap labels and controls in a with class .form-group. Add a class of .control-label to the labels.You can try to run the following code to create a horizontal form in Bootstrap −Example           Bootstrap Example                                                             First Name                                                                         Last Name                                                                                                           Remember me                                                                            Sign in                                

Read More

C# Program to remove duplicate characters from String

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

Use Hashset to remove duplicate characters.Here is the string −string myStr = "kkllmmnnoo";Now, use HashSet to map the string to char. This will remove the duplicate characters from a string.var unique = new HashSet(myStr);Let us see the complete example −Exampleusing System; using System.Linq; using System.Collections.Generic; namespace Demo {    class Program {       static void Main(string[] args) {          string myStr = "kkllmmnnoo";          Console.WriteLine("Initial String: "+myStr);          var unique = new HashSet(myStr);          Console.Write("New String after removing duplicates: ");          foreach (char c in unique)          Console.Write(c);       }    } }OutputInitial String: kkllmmnnoo New String after removing duplicates: klmno

Read More

How to validate a string for a numeric representation using TryParse in C#

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

The following is our string −string myStr = "5";To check whether the above is a string with numeric representation, use TryParse and out.int.TryParse(myStr, out a);Here is the complete code.Exampleusing System.IO; using System; class Program {    static void Main() {       bool res;       int a;       string myStr = "5";       // checking for valid string representation of a number       res = int.TryParse(myStr, out a);       Console.WriteLine(res);    } }OutputTrue

Read More

How to get int value from enum in C#?

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

Firstly, set the enum −public enum Vehicle { Car, Bus, Truck }Now use typecasting to cast an enum to int −int a = (int)Vehicle.Car;The following is the complete code to cast an enum to int −Exampleusing System; public class Demo {    public enum Vehicle { Car, Bus, Truck }    public static void Main() {       int a = (int)Vehicle.Car;       int b = (int)Vehicle.Bus;       int c = (int)Vehicle.Truck;       Console.WriteLine("Car = {0}", a);       Console.WriteLine("Bus = {0}", b);       Console.WriteLine("Truck = {0}", c);    } }OutputCar = 0 Bus = 1 Truck = 2

Read More

Date Parsing using SimpleDateFormat

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

The SimpleDateFormat class has parse() method, which tries to parse a string according to the format stored in the given SimpleDateFormat object.Exampleimport java.util.*; import java.text.*;   public class DateDemo {    public static void main(String args[]) {       SimpleDateFormat ft = new SimpleDateFormat ("yyyy-MM-dd");               String input = args.length == 0 ? "1818-11-11" : args[0];         System.out.print(input + " Parses as ");               Date t;       try {          t = ft.parse(input);                    System.out.println(t);               } catch (ParseException e) {                    System.out.println("Unparseable using " + ft);               }    } }A sample run of the above program would produce the following result −Output1818-11-11 Parses as Wed Nov 11 00:00:00 EST 1818

Read More
Showing 651–660 of 1,421 articles
« Prev 1 64 65 66 67 68 143 Next »
Advertisements