Samual Sam has Published 2310 Articles

SortedMap Interface in C#

Samual Sam

Samual Sam

Updated on 22-Jun-2020 10:23:59

523 Views

Java has SortedMap Interface, whereas an equivalent of it in C# is SortedList.SortedList collection in C# use a key as well as an index to access the items in a list.A sorted list is a combination of an array and a hash table. It contains a list of items that ... Read More

C# program to list the difference between two lists

Samual Sam

Samual Sam

Updated on 22-Jun-2020 10:23:00

2K+ Views

To get the difference between two lists, firstly set two lists in C# −// first list List < string > list1 = new List < string > (); list1.Add("A"); list1.Add("B"); list1.Add("C"); list1.Add("D"); // second list List < string > list2 = new List < string > (); list2.Add("C"); list2.Add("D"); ... Read More

What is the type of elements of the jagged array in C#?

Samual Sam

Samual Sam

Updated on 22-Jun-2020 10:21:04

162 Views

A jagged array is an array of arrays, and therefore its elements are reference types and are initialized to null.Let us see how to work with Jagged array −Declare a jagged array −int [][] marks;Now, let us initialize it, wherein marks is an arrays of 5 integers −int[][] marks = ... Read More

What is unmanaged code in C#?

Samual Sam

Samual Sam

Updated on 22-Jun-2020 10:19:37

627 Views

The following states what is an unmanaged code −Applications that are not under the control of the CLR are unmanagedThe unsafe code or the unmanaged code is a code block that uses a pointer variable.The unsafe modifier allows pointer usage in unmanaged code.Here is the module showing how to declare ... Read More

C# program to convert floating to binary

Samual Sam

Samual Sam

Updated on 22-Jun-2020 10:19:09

784 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; ... Read More

Socket Programming in C#

Samual Sam

Samual Sam

Updated on 22-Jun-2020 10:16:10

2K+ 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 ... Read More

Find frequency of each word in a string in C#

Samual Sam

Samual Sam

Updated on 22-Jun-2020 10:14:23

789 Views

To find the frequency of each word in a string, you can try to run the following code −Example Live Demousing System; class Demo {    static int maxCHARS = 256;    static void calculate(String s, int[] cal) {       for (int i = 0; i < s.Length; i++) ... Read More

How to find the Current Context id of the Thread in C#?

Samual Sam

Samual Sam

Updated on 22-Jun-2020 10:11:35

734 Views

To create a new thread.Thread thread = Thread.CurrentThread; thread.Name = "My new Thread”;To get the current context id, use the ContextID property.Thread.CurrentContext.ContextIDLet us see the complete code −Example Live Demousing System; using System.Threading; namespace Demo {    class MyClass {       static void Main(string[] args) {       ... Read More

Calculate the execution time of a method in C#

Samual Sam

Samual Sam

Updated on 22-Jun-2020 10:09:06

814 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 { ... Read More

How to find Volume and Surface Area of a Sphere using C#?

Samual Sam

Samual Sam

Updated on 22-Jun-2020 10:00:28

354 Views

For volume and surface area of a sphere, firstly declare a variable with the value of radius.int r = 15;Get the volume f the sphere.// calculating volume of sphere cal_volume = (4.0 / 3) * (22 / 7) * r * r * r;Now the surface area of the sphere ... Read More

Advertisements