- 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 2628 Articles for Csharp
![Arjun Thakur](https://www.tutorialspoint.com/assets/profiles/13574/profile/60_74441-1560315595.jpg)
371 Views
Set a linkelist collection −var list = new LinkedList();Now, add elements −list.AddLast("One"); list.AddLast("Two"); list.AddLast("Four");Now, let us add new elements in the already created LinkedList −LinkedListNode node = list.Find("Four"); list.AddBefore(node, "Three"); list.AddAfter(node, "Five");Let us now see how to traverse through the nodes in a Singly Linked List −Exampleusing System; using System.Collections.Generic; public class Demo { public static void Main(string[] args) { var list = new LinkedList < string > (); list.AddLast("One"); list.AddLast("Two"); list.AddLast("Four"); Console.WriteLine("Travering..."); foreach(var res in list) { ... Read More
![Ankith Reddy](https://www.tutorialspoint.com/assets/profiles/22328/profile/60_142162-1519038074.jpg)
183 Views
Firstly, set an array and initialize it −int[] arr = new int[] {34, 56, 12};To loop through all the elements of an array −for (int i = 0; i < arr.Length; i++) { Console.WriteLine(arr[i]); }Let us see the complete code −Exampleusing System; public class Program { public static void Main() { int[] arr = new int[] {34, 56, 12}; // Length Console.WriteLine("Length:" + arr.Length); for (int i = 0; i< arr.Length; i++) { Console.WriteLine(arr[i]); } } }
![George John](https://www.tutorialspoint.com/assets/profiles/13511/profile/60_58410-1512537824.png)
538 Views
To list all the substrings, use the Substring method and loop through the length of the string.Let’s say our string is −string myStr = "pqrz";Use nested loop and get the substring in a new string −for (int i = 1; i < myStr.Length; i++) { for (int start = 0; start
![vanithasree](https://www.tutorialspoint.com/assets/profiles/13547/profile/60_85216-1512542720.jpg)
242 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
![seetha](https://www.tutorialspoint.com/assets/profiles/13549/profile/60_42938-1512640859.jpg)
130 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)
962 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