- 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
![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
![Ankith Reddy](https://www.tutorialspoint.com/assets/profiles/22328/profile/60_142162-1519038074.jpg)
916 Views
Firstly, set an array −int[] arr = { 87, 55, 23, 87, 45, 23, 98 };Now declare a dictionary and loop through the array and get the count of all the elements. The value you get from the dictionary displays the occurrence of numbers −foreach(var count in arr) { if (dict.ContainsKey(count)) dict[count]++; else dict[count] = 1; }Let us see the complete example −Exampleusing System; using System.Collections.Generic; namespace Demo { public class Program { public static void Main(string[] args) { ... Read More
![Samual Sam](https://www.tutorialspoint.com/assets/profiles/13514/profile/60_83486-1512649303.jpg)
554 Views
Let’s say the following is our float −float n = 50.5f;Take an empty string to display the binary value and loop until the value of our float variable is greater than 1 −string a = ""; while (n >= 1) { a = (n % 2) + a; n = n / 2; }Let us see the complete example −Example Live Demousing System; using System.IO; using System.CodeDom.Compiler; namespace Program { class Demo { static void Main(string[] args) { // float to binary Console.WriteLine("float to binary = "); float n = 50.5f; string a = ""; while (n >= 1) { a = (n % 2) + a; n = n / 2; } Console.Write(a); } } }Outputfloat to binary = 1.5781251.156250.31250.6251.250.5
![Arjun Thakur](https://www.tutorialspoint.com/assets/profiles/13574/profile/60_74441-1560315595.jpg)
397 Views
Declare a 2D array −int[] a = new int[] { 65, 45, 32, 97, 23, 75, 59 };Let’s say you want the Kth smallest i.e, 5th smallest integer. Sort the array first −Array.Sort(a);To get the 5th smallest element −a[k - 1];Let us see the complete code −Exampleusing System; using System.IO; using System.CodeDom.Compiler; namespace Program { class Demo { static void Main(string[] args) { int[] a = new int[] { 65, 45, ... Read More
![karthikeya Boyini](https://www.tutorialspoint.com/assets/profiles/13518/profile/60_31598-1537784993.jpg)
1K+ Views
To check if a string is a valid keyword, use the IsValidIdentifier method.The IsValidIdentifier method checks whether the entered value is an identifier or not. If it’s not an identifier, then it’s a keyword in C#.Let us see an example, wherein we have set the CodeDomProvider and worked with the IsValiddentifier method −CodeDomProvider provider = CodeDomProvider.CreateProvider("C#");Let us see the complete codeLExample Live Demousing System; using System.IO; using System.CodeDom.Compiler; namespace Program { class Demo { static void Main(string[] args) { string str1 = "amit"; string str2 = ... Read More
![Ankith Reddy](https://www.tutorialspoint.com/assets/profiles/22328/profile/60_142162-1519038074.jpg)
943 Views
Firstly, create an instance of DriveInfo −DriveInfo dInfo = new DriveInfo("E");Display free space −Console.WriteLine("Disk Free space = {0}", dInfo.AvailableFreeSpace); Now, use AvailableFreeSpace property and get the percentage of free space −Double pc = (dInfo.AvailableFreeSpace / (float)dInfo.TotalSize) * 100;Here, you will get the percentage of free size in comparison with the total disk space −Console.WriteLine(" Free space (percentage) = {0:0.00}%.", pc);
![Samual Sam](https://www.tutorialspoint.com/assets/profiles/13514/profile/60_83486-1512649303.jpg)
632 Views
Use Stopwatch class to measure time of execution of a method in .NET −Stopwatch s = Stopwatch.StartNew();Now set a function and use the ElapsedMilliseconds property to get the execution time in milliseconds −s.ElapsedMillisecondsLet us see the complete code −Example Live Demousing System; using System.IO; using System.Diagnostics; public class Demo { public static void Main(string[] args) { Stopwatch s = Stopwatch.StartNew(); display(); for (int index = 0; index < 5; index++) { Console.WriteLine("Time taken: " + s.ElapsedMilliseconds + "ms"); } ... Read More
![George John](https://www.tutorialspoint.com/assets/profiles/13511/profile/60_58410-1512537824.png)
169 Views
To find the power of a number, firstly set the number and the power −int n = 15; int p = 2;Now create a method and pass these values −static long power(int n, int p) { if (p != 0) { return (n * power(n, p - 1)); } return 1; } Above, the recursive call gave us the results −n * power(n, p - 1)The following is the complete code to get the power of a number −Example Live Demousing System; using System.IO; public class Demo { public static void Main(string[] args) { ... Read More