Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
-
Economics & Finance
Articles by karthikeya Boyini
Page 58 of 143
Bootstrap Horizontal Form
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 MoreC# Program to remove duplicate characters from String
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 MoreHow to validate a string for a numeric representation using TryParse in C#
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 MoreHow to get int value from enum in C#?
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 MoreDate Parsing using SimpleDateFormat
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 MorePrint a 2 D Array or Matrix in C#
First, set a two-dimensional array.int[, ] arr = new int[10, 10];Now, get the elements from the user −for (i = 0; i < m; i++) { for (j = 0; j < n; j++) { arr[i, j] = Convert.ToInt16(Console.ReadLine()); } }Let us see the complete example to display the matrix.Exampleusing System; using System.Linq; class Demo { static void Main() { int m, n, i, j; // rows and columns of the matrix+ m = 2; n = 2; ...
Read MoreHow to remove items from a list in C#?
Firstly, set a list and add elements.List myList = new List(); myList.Add("Jennings"); myList.Add("James"); myList.Add("Chris");Let’s say you need to delete the element “James” now. For that, use the Remove() method.myList.Remove("James");Here is the complete code.Exampleusing System.Collections.Generic; using System; class Program { static void Main() { List myList = new List(); myList.Add("Jennings"); myList.Add("James"); myList.Add("Chris"); Console.WriteLine("Initial List..."); foreach(string str in myList) { Console.WriteLine(str); } myList.Remove("James"); Console.WriteLine("New List..."); ...
Read MoreC# program to print all sublists of a list
Firstly, create a list −List list = new List();The string here is “xyz” for which we will find the sublists. While looping we will declare another list, that would generate sublists on every true iteration −for (int i = 1; i < str.Length; i++) { list.Add(str[i - 1].ToString()); List newlist = new List(); for (int j = 0; j < list.Count; j++) { string list2 = list[j] + str[i]; newlist.Add(list2); } list.AddRange(newlist); }The following is the complete code −Exampleusing System; using System.Collections.Generic; using System.Linq; using System.Text; namespace Demo { ...
Read MoreHow to print the contents of array horizontally using C#?
Set an array.int[] array = new int[] { 50, 100, 150, 200, 250, 300, 350, 400 };Now, if you will print this array using a loop and new line, then the arrays will be visible vertically.To work it horizontally, use the Join() method and set spaces to separate array elements.string.Join(" ", array)Let us see the complete code.Exampleusing System; using System.Linq; using System.IO; class Program { static void Main() { int[] array = new int[] { 50, 100, 150, 200, 250, 300, 350, 400 }; Console.WriteLine(string.Join(" ", array)); } }Output50 100 150 200 250 300 350 400
Read MoreLambda Expressions in C#
A lambda expression in C# describes a pattern.Lambda Expressions has the token => in an expression context. This is read as “goes to” operator and used when a lambda expression is declared.Here, we are finding the first occurrence of the element greater than 50 from a list.list.FindIndex(x => x > 50);Above the token => is used. The same is shown below −Exampleusing System; using System.Collections.Generic; class Demo { static void Main() { List list = new List { 44, 6, 34, 23, 78 }; int res = list.FindIndex(x => x > 50); Console.WriteLine("Index: "+res); } }OutputIndex: 4
Read More