
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

309 Views
Let us say our string is −string str = "3456";Now, to check whether the entered string is a number or not −str.All(c => char.IsDigit(c))The above returns true if the string is a number, else false.Here is the complete code −Example Live Demousing System; using System.Linq; namespace Demo { public class MyApplication { public static void Main(string[] args) { string str = "3456"; // checking if string is a number or not Console.WriteLine(str.All(c => char.IsDigit(c))); } } }OutputTrue

203 Views
Firstly, set an array −int[] arr = {6, 3, 8, 4};Now, use the Length property to get the size of the array −arr.LengthLet us see the complete code −Example Live Demousing System; namespace Demo { public class Demo { public static void Main(string[] args) { int[] arr = {6, 3, 8, 4}; Console.WriteLine("Array..."); foreach (int i in arr) { Console.Write(i + " "); } Console.WriteLine("Size of Array: "+arr.Length); } } }OutputArray... 6 3 8 4 Size of Array: 4

2K+ Views
Firstly, declare a tuple and add values −Tuple tuple = new Tuple(100, "Tom");With C#, to iterate over a tuple, you can go for individual elements −tuple.Item1 // first item tuple.Item2 // second item To display the complete tuple, just use: // display entire tuple Console.WriteLine(tuple);Let us see the complete code −Exampleusing System; using System.Threading; namespace Demo { class Program { static void Main(string[] args) { Tuple tuple = new Tuple(100, "Tom"); if (tuple.Item1 == 100) { Console.WriteLine(tuple.Item1); } if (tuple.Item2 == "Tom") { Console.WriteLine(tuple.Item2); } // display entire tuple Console.WriteLine(tuple); } } }

14K+ Views
To empty a C# list, use the Clear() method.Firstly, set a list and add elements −List myList = new List() { "one", "two", "three", "four", "five", "six" };Now, let us empty the list −myList.Clear();Example Live Demousing System; using System.Collections.Generic; public class Program { public static void Main() { List myList = new List() { "one", "two", "three", "four", "five", "six" }; ... Read More

2K+ Views
Declare a list and add elements −var products = new List < string > (); // adding elements products.Add("Belts"); products.Add("T-Shirt"); products.Add("Trousers");Use a loop to iterate −foreach(var p in products) { Console.WriteLine(p); }ExampleLet us see the complete example −using System; using System.Collections.Generic; public class Demo { public static void Main(string[] args) { var products = new List < string > (); products.Add("Belts"); products.Add("T-Shirt"); products.Add("Trousers"); Console.WriteLine("Our list...."); foreach(var p in products) { Console.WriteLine(p); } } }

5K+ Views
To join two lists, use AddRange() method.Set the first list −var list1 = new List < string > (); list1.Add("Keyboard"); list1.Add("Mouse");Set the second list −var list2 = new List < string > (); list2.Add("Hard Disk"); list2.Add("Pen Drive");To concatenate both the lists −lists1.AddRange(lists2);The following is the complete code −Exampleusing System.Collections.Generic; using System; namespace Demo { public static class Program { public static void Main() { var list1 = new List < string > (); list1.Add("Keyboard"); list1.Add("Mouse"); Console.WriteLine("Our list1...."); ... Read More

1K+ Views
Use the new keyword to instantiate a delegate. When creating a delegate, the argument passed to the new expression is written similar to a method call, but without the arguments to the method.For example −public delegate void printString(string s); printString ps1 = new printString(WriteToScreen);You can also instantiate a delegate using an anonymous method −//declare delegate void Del(string str); Del d = delegate(string name) { Console.WriteLine("Notification received for: {0}", name); };Let us see an example that declare and instantiates a delegate −Example Live Demousing System; delegate int NumberChanger(int n); namespace DelegateAppl { class TestDelegate { ... Read More

3K+ Views
To insert an item in an already created List, use the Insert() method.Firstly, set elements −List list = new List(); list.Add(989); list.Add(345); list.Add(654); list.Add(876); list.Add(234); list.Add(909);Now, let’s say you need to insert an item at 4th position. For that, use the Insert() method −// inserting element at 4th position list.Insert(3, 567);Let us see the complete example −Exampleusing System; using System.Collections.Generic; namespace Demo { public class Program { public static void Main(string[] args) { List < int > list = new List < int > (); ... Read More

3K+ Views
Firstly, set the string −string str = "Football and Tennis";Now, use the substring() method to get the last 4 characters −str.Substring(str.Length - 4);Let us see the complete code −Example Live Demousing System; public class Demo { public static void Main() { string str = "Football and Tennis"; string res = str.Substring(str.Length - 4); Console.WriteLine(res); } }Outputnnis

3K+ Views
To initialize a tuple to an empty tuple −Tuple myTuple;If you want to check for values in a tuple, that whether it is null or not −Exampleusing System; namespace Demo { class Program { static void Main(string[] args) { Tuple tuple = new Tuple(10, null); if (tuple.Item1 == 10) { Console.WriteLine(tuple.Item1); } if (tuple.Item2 == null) { Console.WriteLine("Item is null"); } } } }