- 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
![Ankith Reddy](https://www.tutorialspoint.com/assets/profiles/22328/profile/60_142162-1519038074.jpg)
3K+ Views
To initialize a string to an empty list −string myStr = null;Now, use the built-in method IsNullOrEmpty() to check whether the list is empty or not −if (string.IsNullOrEmpty(myStr)) { Console.WriteLine("String is empty or null!"); }Let us see the complete code −Example Live Demousing System; namespace Demo { class Program { static void Main(string[] args) { string myStr = null; if (string.IsNullOrEmpty(myStr)) { Console.WriteLine("String is empty or null!"); } Console.ReadKey(); ... Read More
![George John](https://www.tutorialspoint.com/assets/profiles/13511/profile/60_58410-1512537824.png)
2K+ Views
Firstly, set a list −List list = new List(); list.Add(456); list.Add(321); list.Add(123); list.Add(877); list.Add(588); list.Add(459);Now, to add an item at index 5, let say; for that, use the Insert() method −list.Insert(5, 999);Let us see the complete example −Exampleusing System; using System.Collections.Generic; namespace Demo { public class Program { public static void Main(string[] args) { List list = new List(); list.Add(456); list.Add(321); list.Add(123); list.Add(877); list.Add(588); list.Add(459); ... Read More
![Chandu yadav](https://www.tutorialspoint.com/assets/profiles/22330/profile/60_142811-1519038104.jpg)
261 Views
An array is used to store a collection of data, but it is often more useful to think of an array as a collection of variables of the same type stored at contiguous memory locations.Multi-dimensional arrays are also called rectangular array. Multidimensional arrays are initialized by specifying bracketed values for each row.The following array is with 2 rows and each row has 2 columns.int [, ] a = new int [2, 2] { {20, 50} , /* initializers for row indexed by 0 */ {15, 45} , /* initializers for row indexed by 1 */ };Let us see an example ... Read More
![karthikeya Boyini](https://www.tutorialspoint.com/assets/profiles/13518/profile/60_31598-1537784993.jpg)
166 Views
To get the status of current thread, use the IsAlive() method −Firstly, create a new thread −Thread t = Thread.CurrentThread; t.Name = "Our Thread";Now, to get the status of the current thread −t.IsAliveThe following is the complete code −Example Live Demousing System; using System.Threading; namespace Demo { class MyClass { static void Main(string[] args) { Thread t = Thread.CurrentThread; t.Name = "Our Thread"; Console.WriteLine("Status = {0}", t.IsAlive); Console.ReadKey(); } } }OutputStatus = True
![Samual Sam](https://www.tutorialspoint.com/assets/profiles/13514/profile/60_83486-1512649303.jpg)
259 Views
The best IDE for C# on Windows is Microsoft Visual Studio. It is an IDE to develop websites, web apps, mobile apps, etc. The following are the features of Visual Studio IDE − Code Editor − Visual Studio has a code editor supporting syntax highlighting and code completion using IntelliSense. Breakpoints − Set breakpoints and allow monitoring the variable values as the execution progress. Extend Capability − With Visual Studio, you can extend the functionality of the IDE. The extension includes macros, packages, etc. Built-in-languages − Visual Studio supports more than 30 programming ... Read More
![karthikeya Boyini](https://www.tutorialspoint.com/assets/profiles/13518/profile/60_31598-1537784993.jpg)
2K+ Views
Check for the following conditions −For odd and even, check for the remainder when the number is divided by 2 −// checking for odd/ even if(n % 2 == 0) { Console.WriteLine("Even"); } else { Console.WriteLine("Odd"); }For positive, negative and checking whether a number is 0 or not −if (n < 0) { Console.WriteLine("Negative Number!"); } else if(n == 0) { Console.WriteLine("Zero"); } else { Console.WriteLine("Positive Number!"); }The following is the complete code:Example Live Demousing System; using System.Collections.Generic; public class Demo { public static void Main(string[] args) { int n = 19; ... Read More
![Samual Sam](https://www.tutorialspoint.com/assets/profiles/13514/profile/60_83486-1512649303.jpg)
2K+ Views
To loop through all the values of enum, use the Enum.GetValues().Firstly, set an Enum −public enum Grade { A, B, C, D, E, F };Now, with foreach loop, you need to loop through Enum.GetValues(typeof(Grade)) −foreach (Grade g in Enum.GetValues(typeof(Grade))) { Console.WriteLine(g); }Here is the complete code −Example Live Demousing System; public class EnumExample { public enum Grade { A, B, C, D, E, F }; public static void Main() { foreach (Grade g in Enum.GetValues(typeof(Grade))) { Console.WriteLine(g); } } }OutputA B C D E F
![karthikeya Boyini](https://www.tutorialspoint.com/assets/profiles/13518/profile/60_31598-1537784993.jpg)
310 Views
Firstly, use the DirectoryInfo object −//creating a DirectoryInfo object DirectoryInfo mydir = new DirectoryInfo(@"d:\amit");Now, use the GetFiles() method to get all the files −FileInfo [] f = mydir.GetFiles();To get the list of files in a directory, try to run the following code −Exampleusing System; using System.IO; namespace Demo { class Program { static void Main(string[] args) { //creating a DirectoryInfo object DirectoryInfo mydir = new DirectoryInfo(@"d:\amit"); // getting the files in the directory, their names and size FileInfo [] f = mydir.GetFiles(); foreach (FileInfo file in f) { Console.WriteLine("File Name: {0} Size: {1}", file.Name, file.Length); } Console.ReadKey(); } } }
![Samual Sam](https://www.tutorialspoint.com/assets/profiles/13514/profile/60_83486-1512649303.jpg)
2K+ Views
To concatenate two lists, use AddRange() method.Set the first list −var products1 = new List < string > (); products1.Add("Belts"); products1.Add("Tshirt"); products1.Add("Trousers");Set the second list −var products2 = new List < string > (); products2.Add("Footwear"); products2.Add("Electronics");To concatenate both the lists −products1.AddRange(products2);The following is the complete code −Example Live Demousing System.Collections.Generic; using System; namespace Demo { public static class Program { public static void Main() { var products1 = new List < string > (); products1.Add("Belts"); products1.Add("Tshirt"); products1.Add("Trousers"); ... Read More
![karthikeya Boyini](https://www.tutorialspoint.com/assets/profiles/13518/profile/60_31598-1537784993.jpg)
354 Views
Firstly, add elements −IDictionary d = new Dictionary(); d.Add(1,97); d.Add(2,89); d.Add(3,77); d.Add(4,88);Now, get the keys −List myList = new List(d.Keys);To iterate −foreach (int k in myList) { Console.WriteLine("{0}, {1}", k, d[k]); }The following is an example −Example Live Demousing System; using System.Collections.Generic; public class Demo { public static void Main() { IDictionary < int, int > d = new Dictionary < int, int > (); d.Add(1, 97); d.Add(2, 89); d.Add(3, 77); d.Add(4, 88); List < int > myList = new List < int > (d.Keys); foreach(int k in myList) { Console.WriteLine("{0}, {1}", k, d[k]); } } }Output1, 97 2, 89 3, 77 4, 88