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 2409 of 2646
326 Views
The ‘for loop’ executes a sequence of statements multiple times and abbreviates the code that manages the loop variable.The following is our for loop.Example Live Demousing System; namespace ArrayApplication { class MyArray { static void Main(string[] args) { int [] n = new int[10]; /* n is an array of 10 integers */ int i, j; /* initialize elements of array n */ for ( i = 0; i < 10; i++ ) { n[ ... Read More
330 Views
To call a C# method recursively, you can try to run the following code. Here, Factorial of a number is what we are finding using a recursive function display().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 1you want the value of 5!Interation1: 5 * display(5 - 1); Interation2: 4 * display(4 - 1); Interation3: 3 * display(3 - 1); Interation4: 4 * display(2 - 1);The following is the complete code to call a C# method recursively.Example Live Demousing System; ... Read More
4K+ Views
A 2-dimensional array can be thought of as a table, which has x number of rows and y number of columns.An element in 2-dimensional array is accessed by using the subscripts. That is, row index and column index of the array.int x = a[1, 1]; Console.WriteLine(x);Let us see an example that shows how to access elements from two-dimensional array.Example Live Demousing System; namespace Demo { class MyArray { static void Main(string[] args) { /* an array with 5 rows and 2 columns*/ int[, ] a = new int[5, 2] ... Read More
890 Views
Delimiters are the commas that you can see in the below string.string str = "Welcome, to, New York";Now set the delimiter separately.char[] newDelimiter = new char[] { ', ' };Use theSplit() method to split the string considering the delimiter as the parameter.str.Split(newDelimiter, StringSplitOptions.None);To split a string with a string deli meter, try to run the following code −Example Live Demousing System; class Program { static void Main() { string str = "Welcome, to, New York"; char[] newDelimiter = new char[] { ', ' }; string[] arr = str.Split(newDelimiter, StringSplitOptions.None); ... Read More
1K+ Views
To split a string suing regular expression, use the Regex.split.Let’s say our string is −string str = "Hello\rWorld";Now use Regex.split to split the string as shown below −tring[] res = Regex.Split(str, "\r");The following is the complete code to split a string using Regular Expression in C#.Example Live Demousing System; using System.Text.RegularExpressions; class Demo { static void Main() { string str = "Hello\rWorld"; string[] res = Regex.Split(str, "\r"); foreach (string word in res) { Console.WriteLine(word); } } }OutputHello World
1K+ Views
Set the string you want to split.string str = "Hello World!";Use the split() method to split the string into separate elements.string[] res = str.Split(' ');The following is the complete code to split a string into elements of a string array in C#.Example Live Demousing System; class Demo { static void Main() { string str = "Hello World!"; string[] res = str.Split(' '); Console.WriteLine("Separate elements:"); foreach (string words in res) { Console.WriteLine(words); } } }OutputSeparate elements: Hello World!
500 Views
Set the list of dictionaries with keys and values.var d = new Dictionary(); d.Add("Zack", 0); d.Add("Akon", 3); d.Add("Jack", 2); d.Add("Tom", 1);Get and sort the keys.var val = d.Keys.ToList(); val.Sort();You can try to run the following code to sort a list of dictionaries by values.Example Live Demousing System; using System.Collections.Generic; using System.Linq; class Demo { static void Main() { var d = new Dictionary(); d.Add("Zack", 0); d.Add("Akon", 3); d.Add("Jack", 2); d.Add("Tom", 1); // Acquire keys and sort them. var val ... Read More
45K+ Views
Firstly, set a list in C#.var list = new List{ "one","two","three","four"};Now get the count of the elements and display randomly.int index = random.Next(list.Count); Console.WriteLine(list[index]);To select a random element from a list in C#, try to run the following code −Example Live Demousing System; using System.Collections.Generic; namespace Demo { class Program { static void Main(string[] args) { var random = new Random(); var list = new List{ "one","two","three","four"}; int index = random.Next(list.Count); Console.WriteLine(list[index]); } } }Outputthree
392 Views
WriteLine() is a method of the Console class defined in the System namespaceThis statement causes the message "Welcome!" to be displayed on the screen as shown below −Example Live Demousing System; namespace Demo { class Test { static void Main(string[] args) { Console.WriteLine("Welcome!"); Console.ReadKey(); } } }OutputWelcome!To display a char array using the Console.WriteLine.Example Live Demousing System; namespace Demo { class Test { static void Main(string[] args) { char[] arr = new char[] { 'W', 'e'}; Console.WriteLine(arr); Console.ReadKey(); } } }OutputWe
594 Views
Serialization/ De-serialization allow communication with another application by sending and receiving data. With XmlSerializer, you can control how objects are encoded into XML. To perform XML Serialization, you need the following two classes − StreamWriter class XmlSerializer class Call the Serialize method with the parameters of the StreamWriter and object to serialize. string myPath = "new.xml"; XmlSerializer s = new XmlSerializer(settings.GetType()); StreamWriter streamWriter = new StreamWriter(myPath); s.Serialize(streamWriter, settings); An XML file is visible with the name “new.xml”. Now to deserialize. MySettings mySettings = new MySettings(); string myPath = "new.xml"; XmlSerializer ... Read More