- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- 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 34488 Articles for Programming
![seetha](https://www.tutorialspoint.com/assets/profiles/13549/profile/60_42938-1512640859.jpg)
131 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
![Chandu yadav](https://www.tutorialspoint.com/assets/profiles/22330/profile/60_142811-1519038104.jpg)
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); } } }
![Giri Raju](https://www.tutorialspoint.com/assets/profiles/13536/profile/60_72105-1512540773.jpg)
13K+ 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
![Arjun Thakur](https://www.tutorialspoint.com/assets/profiles/13574/profile/60_74441-1560315595.jpg)
1K+ 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); } } }
![Ankith Reddy](https://www.tutorialspoint.com/assets/profiles/22328/profile/60_142162-1519038074.jpg)
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
![George John](https://www.tutorialspoint.com/assets/profiles/13511/profile/60_58410-1512537824.png)
966 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
![Sreemaha](https://www.tutorialspoint.com/assets/profiles/13570/profile/60_64977-1512709068.jpg)
905 Views
Set the string −string str = "Cookie and Session";Use the following Regex to get the last 2 characters from string −Regex.Match(str,@"(.{2})\s*$")The following is the code −Example Live Demousing System; using System.Text.RegularExpressions; public class Demo { public static void Main() { string str = "Cookie and Session"; Console.WriteLine(Regex.Match(str,@"(.{2})\s*$")); } }Outputon
![Chandu yadav](https://www.tutorialspoint.com/assets/profiles/22330/profile/60_142811-1519038104.jpg)
2K+ 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
![radhakrishna](https://www.tutorialspoint.com/assets/profiles/13544/profile/60_40618-1512640354.jpg)
2K+ 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
![Arjun Thakur](https://www.tutorialspoint.com/assets/profiles/13574/profile/60_74441-1560315595.jpg)
2K+ 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"); } } } }