Found 2628 Articles for Csharp

C# program to clone or copy a list

karthikeya Boyini
Updated on 22-Jun-2020 09:50:44

234 Views

To copy or clone a C# list, firstly set a list.List < string > myList = new List < string > (); myList.Add("One"); myList.Add("Two");Now declare a string array and use the CopyTo() method to copy.string[] arr = new string[10]; myList.CopyTo(arr);Let us see the complete code to copy a list into a one-dimensional array.Exampleusing System; using System.Collections.Generic; using System.Linq; public class Demo {    public static void Main() {       List < string > myList = new List < string > ();       myList.Add("One");       myList.Add("Two");       myList.Add("Three");       myList.Add("Four"); ... Read More

C# program to check the validity of a Password

George John
Updated on 22-Jun-2020 09:51:05

6K+ Views

For validity of a password, you need to recall the concept when your create a password to signup to a website.While creating a password, you may have seen the validation requirements on a website like a password should be strong and have −Min 8 char and max 14 charOne upper caseOne special charOne lower caseNo white spaceLet us see how to check the conditions one by one.Min 8 char and max 14 charif (passwd.Length < 8 || passwd.Length > 14) return false;One upper caseif (!passwd.Any(char.IsUpper)) return false;Atleast one lower caseif (!passwd.Any(char.IsLower)) return false;No white spaceif (passwd.Contains(" ")) return false;Check for ... Read More

Threads and Thread Synchronization in C#

Samual Sam
Updated on 22-Jun-2020 09:51:18

557 Views

Using Synchronization, you can synchronize access to resources in multithreaded applications.A 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.Thread pool in C# is a collection of threads. It is used to perform tasks in the background. When a thread completes a task, it is sent to ... Read More

How to compile and execute C# programs on Windows?

Chandu yadav
Updated on 22-Jun-2020 09:38:14

1K+ Views

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

How to compile and execute C# programs on Linux?

Arjun Thakur
Updated on 22-Jun-2020 09:38:54

1K+ Views

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

How to compile and execute C# programs on Mac OS?

karthikeya Boyini
Updated on 22-Jun-2020 09:38:39

1K+ Views

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

Sorting a String in C#

Samual Sam
Updated on 22-Jun-2020 09:41:20

4K+ Views

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

Reverse a Stack using C#

Ankith Reddy
Updated on 22-Jun-2020 09:39:38

3K+ Views

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

Thread Safe Concurrent Collection in C#

karthikeya Boyini
Updated on 22-Jun-2020 09:42:10

968 Views

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

What is the equivalent of a VB module in C#?

George John
Updated on 22-Jun-2020 09:42:31

733 Views

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!");    } }

Advertisements