Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Server Side Programming Articles - Page 2486 of 2646
413 Views
Firstly, set a a new ArrayList and add elements to it.ArrayList arr = new ArrayList(); arr.Add( "Jones" ); arr.Add( "Tom" ); arr.Add( "Henry" );Now let’s remove the item “Tom”. For that, use the Remove() method.arr.Remove("Tom");The following is the complete example to remove an element from ArrayList −Example Live Demousing System; using System.Collections; class Demo { static void Main(){ ArrayList arr = new ArrayList(); arr.Add( "Jones" ); arr.Add( "Tom" ); arr.Add( "Henry" ); Console.WriteLine("Initial ArrayList..."); foreach(string str in arr) { ... Read More
2K+ Views
Declare a new ArrayList and add elements to it.ArrayList arr = new ArrayList(); arr.Add( "One" ); arr.Add( "Two" ); arr.Add( "Three" ); arr.Add( "Four" );Now let’s say you need to remove the element “Three”. For that, use the Remove() method.arr.Remove("Three");The following is the complete example to remove an element from ArrayList −Example Live Demousing System; using System.Collections; class Demo { static void Main() { ArrayList arr = new ArrayList(); arr.Add( "One" ); arr.Add( "Two" ); arr.Add( "Three" ); arr.Add( "Four" ); ... Read More
569 Views
Firstly, declare and initialize one dimensional array.int[] arr = { 35, 12, 66, 90, 34, 2, 64 };Now, use the following to reverse −Array.Reverse(arr);The following is the complete code to reverse a one-dimensional array;Example Live Demousing System; class Demo { static void Main() { int[] arr = { 76, 12, 66, 90, 34, 2, 64 }; // Initial Array Console.WriteLine("Original Array= "); foreach (int i in arr) { Console.WriteLine(i); } // Reverse Array Array.Reverse(arr); Console.WriteLine("Reversed Array= "); foreach (int j in arr) { Console.WriteLine(j); } Console.ReadLine(); } }OutputOriginal Array= 76 12 66 90 34 2 64 Reversed Array= 64 2 34 90 66 12 76
5K+ Views
Set maximum value for char.static int maxCHARS = 256;Now display the duplicate characters in the string.String s = "Welcometomywebsite!"; int []cal = new int[maxCHARS]; calculate(s, cal); for (int i = 0; i < maxCHARS; i++) if(cal[i] > 1) { Console.WriteLine("Character "+(char)i); Console.WriteLine("Occurrence = " + cal[i] + " times"); }Above, we have calculated the frequency of characters. The same is shown below in the complete example −Exampleusing System; class Demo { static int maxCHARS = 256; static void calculate(String s, int[] cal) { for (int i = 0; i < ... Read More
13K+ Views
To remove an item from a list in C# using index, use the RemoveAt() method.Firstly, set the list −List list1 = new List() { "Hanks", "Lawrence", "Beckham", "Cooper", };Now remove the element at 2nd position i.e. index 1list1.RemoveAt(1);Let us see the complete example −Example Live Demousing System; using System.Collections.Generic; using System.Linq; class Program { static void Main() { List list1 = new List() { "Hanks", "Lawrence", "Beckham", "Cooper", }; ... Read More
9K+ Views
To read inputs as strings in C#, use the Console.ReadLine() method.str = Console.ReadLine();The above will read input as string. You don’t need to use the Convert method here since the input takes string by default.Now display the string entered by user −Example Live Demousing System; using System.Collections.Generic; class Demo { static void Main() { string myStr; // use ReadLine() to read the entered line myStr = Console.ReadLine(); // display the line Console.WriteLine("Result = {0}", myStr); } }OutputResult =The following is the output. Let’s say the user entered “Amit” as the input −Result = amit
353 Views
Firstly, set the characters.char[] arr = new char[5]; arr[0] = 'Y'; arr[1] = 'E'; arr[2] = 'S';Now, convert them into string.string res = new string(arr);The following is the complete code to convert a list of characters into a string −Example Live Demousing System; class Program { static void Main() { char[] arr = new char[5]; arr[0] = 'Y'; arr[1] = 'E'; arr[2] = 'S'; // converting to string string res = new string(arr); Console.WriteLine(res); } }OutputYES
32K+ Views
To read inputs as integers in C#, use the Convert.ToInt32() method.res = Convert.ToInt32(val);Let us see how −The Convert.ToInt32 converts the specified string representation of a number to an equivalent 32-bit signed integer.Firstly, read the console input −string val; val = Console.ReadLine();After reading, convert it to an integer.int res; res = Convert.ToInt32(val);Let us see an example −Example Live Demousing System; using System.Collections.Generic; class Demo { static void Main() { string val; int res; Console.WriteLine("Input from user: "); val = Console.ReadLine(); // convert ... Read More
2K+ Views
The ReadLine() method is used to read a line from the console in C#.str = Console.ReadLine();The above will set the line in the variable str.Example Live Demousing System; using System.Collections.Generic; class Demo { static void Main() { string str; // use ReadLine() to read the entered line str = Console.ReadLine(); // display the line Console.WriteLine("Input = {0}", str); } }OutputInput =Above, we displayed a line using the Console.ReadLine() method. The string is entered by the user from the command line.