All these keywords are part of the main method of any C# program.The Main method, which is the entry point for all C# programs states that what a class does when it executed.using System; class Demo { static void Main(string[] args) { Console.WriteLine("My first program in C#!"); } }public − This is the access specifier that states that the method can be accesses publically.static − Here, the object is not required to access static members.void − This states that the method doesn’t return any value.main − is As stated above, it s the entry point of a C# ... Read More
The Mutex class in C# is a synchronization primitive that can also be used for interprocess synchronization.Let us see how to create a new Mutex.private static Mutex m = new Mutex();Let us now see how to initialize a new instance of the Mutex class with a Boolean value.private static Mutex m = new Mutex(true);Now let us see how to initialize a new instance of the Mutex class with a Boolean value and the name of the Mutex.Example Live Demousing System; using System.Threading; public class Demo { public static void Main() { Mutex mt = new Mutex(false, ... Read More
In VB, a module is used to store loose code accessible from elsewhere in the application without having to first initialize something.The state of the variable can be easily set or changed and that continues to carry on that value throughout.For the same work in C#< use a static class.Let us see an example −VBModule MyModule Public Sub Display MsgBox("Demo!") End Sub End ModuleC#public static class Display { public static void DisplayMethod() { Console.WriteLine("Demo!"); } }
The .NET Framework 4 brought the System.Collections.Concurrent namespace. This has several collection classes that are thread-safe and scalable. These collections are called concurrent collections because they can be accessed by multiple threads at a time.The following are the concurrent collection in C# −Sr.NoType & Description1BlockingCollectionBounding and blocking functionality for any type.2ConcurrentDictionaryThread-safe implementation of a dictionary of key-value pairs.3ConcurrentQueueThread-safe implementation of a FIFO (first-in, first-out) queue.4ConcurrentStackThread-safe implementation of a LIFO (last-in, first-out) stack.5ConcurrentBagThread-safe implementation of an unordered collection of elements.6IProducerConsumerCollectionThe interface that a type must implement to be used in a BlockingCollectionLet us see how to work with ConcurrentStack that is ... Read More
Firstly, set a string array.string[] values = { "tim", "amit", "tom", "jack", "saurav"};Use the Sort() method to sort.Array.Sort(values);Let us see the complete code −Example Live Demousing System; public class Program { public static void Main() { string[] values = { "tim", "amit", "tom", "jack", "saurav"}; foreach (string value in values) { Console.Write(value); Console.Write(' '); } // sorting Array.Sort(values); Console.WriteLine("Sorted..."); foreach (string value in values) { Console.Write(value); Console.Write(' '); } Console.WriteLine(); } }Outputtim amit tom jack saurav Sorted... amit jack saurav tim tom
Set a stack and add elements to it.Stack st = new Stack(); st.Push('P'); st.Push('Q'); st.Push('R');Now set another stack to reverse it.Stack rev = new Stack();Until the count of ths Stack is not equal to 0, use the Push and Pop method to reverse it.while (st.Count != 0) { rev.Push(st.Pop()); }The following is the complete code −Example Live Demousing System; using System.Collections; namespace CollectionsApplication { public class Program { public static void Main(string[] args) { Stack st = new Stack(); Stack rev = new Stack(); ... Read More
To compile and execute C# programs on Linux, firstly you need to IDE. On Linux, one of the best IDEs is Monodevelop.It is an open source IDE that allows you to run C# on multiple platforms i.e. Windows, Linux and MacOS. Monodevelop is also known as Xamarin Studio. It has a C# compiler to run C# programs.Monodevelop has the following features −Multi-platform IDE − Supports Linux, Windows and macOS.Supports multiple languages − MonoDevelop supports multiple languages such as C#, F#, Visual Basic .NET, etc.Integrated Debugger − It comes with an integrated debugger for debugging Mono and native applications.Code Completion − ... Read More
To compile and execute C# programs on Mac, firstly you need to IDE. On MacOS, one of the best IDEs is Monodevelop.Monodevelop is an open source IDE that allows you to run C# on multiple platforms i.e. Windows, Linux, and MacOS. MonoDevelop is also known as Xamarin Studio.Monodevelop has a C# compiler to run C# programs. It can be used on Windows, macOS and Linux.For Mac, a special version of MonoDevelop was introduced and it was called Visual Studio for Mac. It has many of the features of what the same IDE provides for Windows like a tool for and ... Read More
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 languages, including C#, F#, JavaScript, TypeScript, etc.Here are the steps to compile ... Read More
Take two arrays:int[] arr2 = new int[5]; int[] arr3 = new int[5];Now, if the array element gets the remainder 0 on dividing by 2, it is even. Get those elements and add in another array. This loops through the length of the array:if (arr1[i] % 2 == 0) { arr2[j] = arr1[i]; }In the else condition, you will get the odd elements. Add them to a separate array and display them individually as shown in the below example:Example Live Demousing System; namespace Demo { public class Program { public static void Main(string[] args) { ... Read More
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP