- 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
![Arjun Thakur](https://www.tutorialspoint.com/assets/profiles/13574/profile/60_74441-1560315595.jpg)
786 Views
Firstly, set a string array −string[] arr = new string[] { "Indian", "Moroccon", "American", };To sort the words in lexicographical order −var sort = from a in arr orderby a select a;Example Live DemoLet us see the complete code −using System; using System.Linq; class Program { static void Main() { string[] arr = new string[] { "Indian", "Moroccon", "American", }; var sort = from a in arr orderby a select a; foreach(string res in sort) { Console.WriteLine(res); } } }outputAmerican Indian Moroccon
![karthikeya Boyini](https://www.tutorialspoint.com/assets/profiles/13518/profile/60_31598-1537784993.jpg)
337 Views
Declare an array and initialize −int[] arr = new int[] { 87, 23, 65, 29, 67 };To sort, use the Sort() method and CompareTo() to compare and display in decreasing order −Array.Sort < int > (arr, new Comparison < int > ((val1, val2) => val2.CompareTo(val1)));Let us see the complete code −Example Live Demousing System; using System.Collections.Generic; using System.Text; public class Demo { public static void Main(string[] args) { int[] arr = new int[] { 87, 23, 65, ... Read More
![George John](https://www.tutorialspoint.com/assets/profiles/13511/profile/60_58410-1512537824.png)
531 Views
ReaderWriterLock synchronize access to a resource. A ReaderWriterLock has better throughput than a Monitor, which is one-at-a-time lock. This works for a situation when a resource is changed rarely. Let us see how to declare a ReaderWriter lock in C# − static ReaderWriterLock r = new ReaderWriterLock(); The following are the properties of a ReaderWriter lock in C# − Sr.No. Property & Description 1 IsReaderLockHeld Gets a value indicating whether the current thread holds a reader lock. 2 IsWriterLockHeld Gets a value indicating whether the current thread holds a Writer lock. ... Read More
![Samual Sam](https://www.tutorialspoint.com/assets/profiles/13514/profile/60_83486-1512649303.jpg)
926 Views
Unit testing is a key for C# code since it can help in maintaining code in the development process. It lets you know about the problems in the development cycle. With Unit Testing, you can make the code reliable and reusable. One of the fundamental principles of adopting unit testing is to follow a TDD (Test Driven Development) approach where we have to write tests case first, and then write the simple code that will make the test pass For Unit testing, you need to work with Microsoft Testing tools, which is what we call MS Unit Test. To create ... Read More
![Arjun Thakur](https://www.tutorialspoint.com/assets/profiles/13574/profile/60_74441-1560315595.jpg)
658 Views
The .NET Framework 4 introduced System.Collections.Concurrent namespace. The namespace has numerous collection classes. These classes are both thread-safe and scalable. Multiple threads can safely add or remove items from these collections, The following concurrent collection types use lightweight synchronization mechanisms: SpinLock, SpinWait, etc. These are new in .NET Framework 4. Let us see the concurrent collection in C# − Sr.No. Type & Description 1 BlockingCollection Bounding and blocking functionality for any type. 2 ConcurrentDictionary Thread-safe implementation of a dictionary of key-value pairs. 3 ConcurrentQueue Thread-safe implementation of a FIFO ... Read More
![karthikeya Boyini](https://www.tutorialspoint.com/assets/profiles/13518/profile/60_31598-1537784993.jpg)
878 Views
In C#, Task parallelism divide tasks. The tasks are then allocated to separate threads for processing. In .NET, you have the following mechanisms to run code in parallel: Thread, ThreadPool, and Task. For parallelism, use tasks in C# instead of Threads.A task will not create its own OS thread, whereas they are executed by a TaskScheduler.Let us see how to create tasks. Use a delegate to start a task −Task tsk = new Task(delegate { PrintMessage(); }); tsk.Start();Use Task Factory to start a task −Task.Factory.StartNew(() => {Console.WriteLine("Welcome!"); });You can also use Lambda −Task tsk = new Task( () => PrintMessage() ... Read More
![Chandu yadav](https://www.tutorialspoint.com/assets/profiles/22330/profile/60_142811-1519038104.jpg)
469 Views
Synchronize access to resources in multithreaded applications using Synchronization.Mutex to Synchronize ThreadsA mutex can be used to synchronize threads across processes. Use it to prevent the simultaneous execution of a block of code by more than one thread at a time.C# lock statement is used to ensure that a block of code runs without interruption by other threads. A Mutual-exclusion lock is obtained for a given object for the duration of the code block.A lock statement gets an object as an argument. The parameter given to the “lock” should be an object based on a reference type −public class Demo ... Read More
![Samual Sam](https://www.tutorialspoint.com/assets/profiles/13514/profile/60_83486-1512649303.jpg)
1K+ Views
The System.Net.Sockets namespace has a managed implementation of the Windows Sockets interface.It has two basic modes − synchronous and asynchronous.Let us see an example to work with System.Net.Sockets.TcpListener class −TcpListener l = new TcpListener(1234); l.Start(); // creating a socket Socket s = l.AcceptSocket(); Stream network = new NetworkStream(s);The following is the Socket useful in communicating on TCP/IP network −Socket s = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp); Above, AddressFamily − It is the standard address families by the Socket class to resolve network addressesSocketType − The type of socketProtocolType − This is the network protocol for communication on the Socket. It ... Read More
![George John](https://www.tutorialspoint.com/assets/profiles/13511/profile/60_58410-1512537824.png)
143 Views
Declare a LinkedList using the LinkedList collection in X# −var a = new LinkedList < string > ();Now add elements to the LinkedList −a.AddLast("Tim"); a.AddLast("Tom");Let us see how to perform traversal in a LinkedList −Exampleusing System; using System.Collections.Generic; public class Demo { public static void Main(string[] args) { var a = new LinkedList < string > (); a.AddLast("Tim"); a.AddLast("Tom"); foreach(var res in a) { Console.WriteLine(res); } } }
![karthikeya Boyini](https://www.tutorialspoint.com/assets/profiles/13518/profile/60_31598-1537784993.jpg)
3K+ Views
Singleton Class allow for single allocations and instances of data. It has normal methods and you can call it using an instance.To prevent multiple instances of the class, the private constructor is used.Let us see an example −public class Singleton { static Singleton b = null; private Singleton() { } }The following is another example displaying how to display Singleton class −Example Live Demousing System; class Singleton { public static readonly Singleton _obj = new Singleton(); public void Display() { Console.WriteLine(true); } Singleton() {} } class Demo { public static void Main() { Singleton._obj.Display(); } }OutputTrue