- 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
![mkotla](https://www.tutorialspoint.com/assets/profiles/13540/profile/60_41073-1512640012.jpg)
6K+ Views
Sets in C# is a HashSet. HashSet in C# eliminates duplicate strings or elements in an array. In C#, it is an optimized set collectionTo declare HashSet −var h = new HashSet(arr1);Above, we have set the already declared array arr1 in the HashSet.Now set it on the array to remove the duplicate words −string[] arr2 = h.ToArray();Let us see an example to remove duplicate strings using C# HashSet.Here, we have duplicate elements −Exampleusing System; using System.Collections.Generic; using System.Linq; class Program { static void Main() { string[] arr1 = {"Table", "Chair", "Pen", "Clip", "Table"}; ... Read More
![varma](https://www.tutorialspoint.com/assets/profiles/13568/profile/60_26300-1512638592.jpg)
628 Views
Main ThreadThe first thread to be executed in a process is called the main thread. When a C# program starts execution, the main thread is automatically created.Child ThreadThe threads created using the Thread class are called the child threads of the main thread.Here is an example showing how to create a main and child thread −Example Live Demousing System; using System.Threading; namespace Demo { class Program { static void Main(string[] args) { Thread th = Thread.CurrentThread; th.Name = "MainThread"; Console.WriteLine("This is {0}", th.Name); Console.ReadKey(); } } }OutputThis is MainThread
![varun](https://www.tutorialspoint.com/assets/profiles/13559/profile/60_29674-1512637943.jpg)
420 Views
The Main method is the entry point for all C# programs. It states what the class does when executed.The valid variant of Main() is −static void Main(string[] argsHere,static − the object is not needed to access static membersvoid − return type of the methodMain − entry point for any C# program. Program execution begins here.string[] args − for command line arguments in C#.ExampleHere is an example −using System; namespace Program { public class Demo { public static void Main(string[] args) { Console.WriteLine("Welcome!"); Console.ReadKey(); } } }
![George John](https://www.tutorialspoint.com/assets/profiles/13511/profile/60_58410-1512537824.png)
245 Views
Let’s say our string is −string str ="9999";Now, use the Int32.Parse() to convert the string into integer −int n = Int32.Parse(str);Now display the integer value as shown in the following code −Exampleusing System; class Demo { static void Main() { string str ="9999"; int n = Int32.Parse(str); Console.WriteLine(n); } }
![Arjun Thakur](https://www.tutorialspoint.com/assets/profiles/13574/profile/60_74441-1560315595.jpg)
135 Views
Let us first set an array of 5 characters −char[] ch = new char[15]; ch[0] = 'T'; ch[1] = 'r'; ch[2] = 'i'; ch[3] = 'c'; ch[4] = 'k';Now convert them into a string −string str = new string(ch);Here is the complete code −ExampleUsing System; class Program { static void Main() { char[] ch = new char[15]; ch[0] = 'T'; ch[1] = 'r'; ch[2] = 'i'; ch[3] = 'c'; ch[4] = 'k'; // converting to string string str = new string(ch); Console.WriteLine(str); } }
![Chandu yadav](https://www.tutorialspoint.com/assets/profiles/22330/profile/60_142811-1519038104.jpg)
355 Views
A list is a Generic collection to hold elements of same datatypes.To clone a list, you can use the CopyTo method.Declare a list and add elements −List < string > myList = new List < string > (); myList.Add("Programming"); myList.Add("Web Dev"); myList.Add("Database");Now create a new array and clone the list into it −string[] arr = new string[10]; myList.CopyTo(arr);Here is the complete code −Example Live Demousing System; using System.Collections.Generic; public class Demo { public static void Main() { List < string > myList = new List < string > (); myList.Add("Programming"); ... Read More
![Arjun Thakur](https://www.tutorialspoint.com/assets/profiles/13574/profile/60_74441-1560315595.jpg)
3K+ Views
The semaphore class lets you set a limit on the number of threads that have access to a critical section. The class is used to control access to a pool of resources. System.Threading.Semaphore is the namespace for Semaphore because it has all the methods and properties required to implement Semaphore.For using a semaphore in C#, you just need to instantiate an instance of a Semaphore object. It has minimum of two arguments −Reference−MSDNSr.No.Constructor & Description1Semaphore(Int32, Int32)Initializes a new instance of the Semaphore class, specifying the initial number of entries and the maximum number of concurrent entries.2Semaphore(Int32, Int32, String) −Initializes a ... Read More
![Ankith Reddy](https://www.tutorialspoint.com/assets/profiles/22328/profile/60_142162-1519038074.jpg)
209 Views
Use the ArrayList.Synchronized Method in C# for synchronization of ArrayList in C#.Let us see an example to lock the collection using SyncRoot property in C# −ArrayList arr = new ArrayList(); lock(arr.SyncRoot) { foreach (object ele in arr) { } }The following is the complete example to check the synchronization status of ArrayList −Example Live Demousing System; using System.Collections; public class Demo { public static void Main() { ArrayList arr1 = new ArrayList(); arr1.Add("One"); arr1.Add("Two"); arr1.Add("Three"); arr1.Add("Four"); arr1.Add("Five"); ... Read More
![George John](https://www.tutorialspoint.com/assets/profiles/13511/profile/60_58410-1512537824.png)
1K+ Views
Deadlock occurs when a resource is locked by a thread and is required by another thread at the same time. This problem occur frequenty in a multiprocessing system.It can occur when two or more threads wait for a resource that belon to another thread. Here is an example −Thread OneThread TwoTakes Lock PTakes Lock QRequests Lock QRequests Lock PThread One will not get Lock Q since it belongs to Thread Two. In the same way, Thread Two won’t get Lock P since its original owner is Thread One.Deadlocks can also be a three-way deadlock that occurs if three threads and ... Read More
![Chandu yadav](https://www.tutorialspoint.com/assets/profiles/22330/profile/60_142811-1519038104.jpg)
1K+ Views
Set the two dictionaries −Dictionary < string, int > dict1 = new Dictionary < string, int > (); dict1.Add("laptop", 1); dict1.Add("desktop", 2); Dictionary < string, int > dict2 = new Dictionary < string, int > (); dict2.Add("desktop", 3); dict2.Add("tablet", 4); dict2.Add("mobile", 5);Now use HashSet and UnionWith() method to merge the two dictionaries −HashSet < string > hSet = new HashSet < string > (dict1.Keys); hSet.UnionWith(dict2.Keys);Here is the complete code −Exampleusing System; using System.Collections.Generic; class Program { static void Main() { Dictionary < string, int > dict1 = new Dictionary < string, int > (); ... Read More