
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
Found 2587 Articles for Csharp

267 Views
To merge two sorted arrays into a list, firstly set two sorted arrays −int[] array1 = { 1, 2 }; int[] array2 = { 3, 4 };Add it to a list and merge −var list = new List(); for (int i = 0; i < array1.Length; i++) { list.Add(array1[i]); list.Add(array2[i]); }Now, use the ToArray() method to convert back into an array as shown below −Example Live Demousing System; using System.Collections.Generic; public class Program { public static void Main() { int[] array1 = { 56, 70, 77}; int[] array2 = ... Read More

571 Views
To check for all vowels, firstly set the condition to check −string res = str.Where(chk =< "aeiouAEIOU".Contains(chk)).Distinct();Above, we have used the string −string str = "the quick brown fox jumps over the lazy dog";Now, using the Any() method checks whether the string has any vowels or not −if(!res.Any()) Console.WriteLine("No vowels!");Loop through the string to get the vowels −Example Live Demousing System; using System.Linq; public class Program { public static void Main() { string str = "the quick brown fox jumps over the lazy dog"; var res = str.Where(chk =< "aeiouAEIOU".Contains(chk)).Distinct(); ... Read More

1K+ Views
Firstly, set the list −List myList = new List () { 5, 10, 7 };Now, set the value of a variable to 1 that would help us in multiplying −int prod = 1;Loop through and get the product −foreach(int i in myList) { prod = prod*i; }The following is the code −Example Live Demousing System; using System.Collections.Generic; public class Program { public static void Main() { List myList = new List() { 5, 10, 7 }; Console.WriteLine("List: "); foreach(int i in myList) { Console.WriteLine(i); } int prod = 1; foreach(int i in myList) { prod = prod*i; } Console.WriteLine("Product: {0}",prod); } }OutputList: 5 10 7 Product: 350

2K+ Views
Firstly, set the number as string −string num = "1000000.8765";Now, work around differently for number before and after the decimal −string withoutDecimals = num.Substring(0, num.IndexOf(".")); string withDecimals = num.Substring(num.IndexOf("."));Use the ToString() method to set the format for 1000 separators −ToString("#,##0")The following is the complete code to display number with commas as 1000 separators −Example Live Demousing System; public class Program { public static void Main() { string num = "1000000.8765"; string withoutDecimals = num.Substring(0, num.IndexOf(".")); string withDecimals = num.Substring(num.IndexOf(".")); withoutDecimals = Convert.ToInt32(withoutDecimals).ToString("#,##0"); Console.WriteLine(withoutDecimals + withDecimals); } }Output1,000,000.8765

1K+ Views
Let’s say the string is −string str = "Never Give Up!";Firstly, split each word −string[] strSplit = str.Split();Now, loop through each word and use the substring method to display the first letter as shown in the following code −Example Live Demousing System; public class Program { public static void Main() { string str = "Never Give Up!"; Console.WriteLine("Initial String= "+str); Console.WriteLine("Displaying first letter of each word..."); string[] strSplit = str.Split(); foreach (string res in strSplit) { Console.Write(res.Substring(0,1)); } } }OutputInitial String= Never Give Up! Displaying first letter of each word... NGU

501 Views
Use the Intesect method to get the common elements −Create lists −var list1 = new List{99, 87}; var list2 = new List{56, 87, 45, 99};Now, use the Intersect() method to get the common elements from the above list −list1.Intersect(list2);Here is the complete code −Example Live Demousing System.Collections.Generic; using System.Linq; using System; public class Demo { public static void Main() { // two lists var list1 = new List{99, 87}; var list2 = new List{56, 87, 45, 99}; // common values var res = list1.Intersect(list2); foreach(int i in res) { Console.WriteLine(i); } } }Output99 87

460 Views
Let’s say our string is −string str = "The Shape of Water got an Oscar Award!";Use the following Regular Expression to display first letter of each word −@"\b[a-zA-Z]"Here is the complete code −Example Live Demousing System; using System.Text.RegularExpressions; namespace RegExApplication { public class Program { private static void showMatch(string text, string expr) { Console.WriteLine("The Expression: " + expr); MatchCollection mc = Regex.Matches(text, expr); foreach (Match m in mc) { Console.WriteLine(m); } } ... Read More

325 Views
Java’s Double Brace Initialization does the same work what a single brace can achieve in C#.Double Brace creates and initialize objects in a single Java expression.Let’s say the following is in Java −ExampleList list = new List() {{ add("One"); add("Two"); add("Three"); add("Four"); }}The same you can use for Collection Initializer in C# as −List list = new List() {"One","Two", “Three”, “Four”};