Found 2587 Articles for Csharp

Explain C# Quantifiers in regular expression

Chandu yadav
Updated on 30-Jul-2019 22:30:23

419 Views

Quantifiers in C# specify how many instances of the previous element (which can be a character, a group, or a character class) must be present in the input string for a match to occur. Quantifier Description Pattern Matches * Matches the previous element zero or more times. \d*\.\d ".0", "19.9", "219.9" + Matches the previous element one or more times. "be+" "bee" in "been", "be" in "bent" ? Matches the previous element zero or one time. "rai?n" "ran", "rain" { n } Matches the previous element exactly n ... Read More

Debug Class vs Debugger Class in C#

karthikeya Boyini
Updated on 30-Jul-2019 22:30:23

373 Views

To debug your code, you need methods or properties, which are provided by Debug Class in C#. The debugger class is used to set communication with the debugger. Debug Class The Debug class inherits from System.Diagnostics. The syntax is − public static class Debug The following are the properties of the debugger class. Sr.No Property & Description 1 AutoFlush Gets or sets a value stating whether Flush should be called on the Listeners or not. 2 IndentLevel The indent level is set 3 IndetntSize The number of spaces in the ... Read More

Delete nth element from headnode using C#

George John
Updated on 23-Jun-2020 11:22:41

155 Views

Firstly, set a link list and add some elements.Demo list = new Demo(); list.Push(50); list.Push(100); list.Push(150);Now to delete nth element from headnode, pass what you want to delete. If you will set 1, then it will delete the head node.Exampleif (val == 1) {    head = head.Next;    return; } // n points to the node before the node we wish to delete Node n = head; // m is the node set to be deleted Node m = head.Next; for (int i = 2; i < val; i++) {    n = n.Next;    m = m.Next; } ... Read More

Dictionary Methods in C#

Samual Sam
Updated on 23-Jun-2020 11:26:04

5K+ Views

Dictionary is a collection of keys and values in C#. Dictionary is included in the System.Collection.Generics namespace.The following are the methods −Sr.NoMethod & Description1AddAdd key-value pairs in Dictionary2Clear()Remove all keys and values3RemoveRemoves the element with the specified key.4ContainsKeyChecks whether the specified key exists in Dictionary.5ContainsValueChecks whether the specified key value exists in Dictionary.6CountCount the number of key-value pairs.7ClearRemoves all the elements from Dictionary.Let us see how to add elements into a Dictionary and display the count.Example Live Demousing System; using System.Collections.Generic; public class Demo {    public static void Main() {       IDictionary d = new Dictionary();     ... Read More

Exception Propagation in C#

Ankith Reddy
Updated on 23-Jun-2020 11:25:19

1K+ Views

Exception Propogation can be understood by how exception handling works in C#.In try, when an exception occurs the corresponding catch blocks are checked. This is done to see if they can catch the exception. If no matching exception is found, the exception is propagated to a higher-level try block. This repeats until the exception is caught. In case, the exception isn’t caught, the execution of the program comes to an end.The above concept is explain in the below example showing nested try statements.Example Live Demousing System; using System.Text; public class Demo {    public static void Main() {       ... Read More

Different ways to start a Task in C#

karthikeya Boyini
Updated on 30-Jul-2019 22:30:23

9K+ Views

To start a task in C#, follow any of the below given ways. Use a delegate to start a task. Task t = new Task(delegate { PrintMessage(); }); t.Start(); Use Task Factory to start a task. Task.Factory.StartNew(() => {Console.WriteLine("Welcome!"); }); You can also use Lambda. Task t = new Task( () => PrintMessage() ); t.Start();

What is the Keys property of SortedList class in C#?

Arjun Thakur
Updated on 23-Jun-2020 10:49:39

99 Views

Get the keys in the SortedList using the keys property of SortedList class in C#. We have first set the SortedList property with elements.SortedList sl = new SortedList(); sl.Add("ST0", "One"); sl.Add("ST1", "Two"); sl.Add("ST2", "Three"); sl.Add("ST3", "Four"); sl.Add("ST4", "Five"); sl.Add("ST5", "Six"); sl.Add("ST6", "Seven");Now use the keys property to get the keys.ICollection key = sl.Keys;The following is the complete code to implement keys property of SortedList class.Example Live Demousing System; using System.Collections; namespace Demo {    class Program {       static void Main(string[] args) {          SortedList sl = new SortedList();          sl.Add("ST0", "One");   ... Read More

Dynamic Binding in C#

Chandu yadav
Updated on 23-Jun-2020 11:02:14

1K+ Views

In Dynamic binding, the compiler will not do type checking at compile time. At run time, the checking is done.Use it to avoid the restriction of anonymous types to one method. This is only because the type name is visible only to the compiler; therefore, you cannot declare it as the return value of a method.Examplepublic dynamic GetAnonymousType() {    return new {       StudentName = "Tom",       Subject = "Java",    }; }Above, the method is set to be dynamic, that would means the compiler won’t do type checking at compile time.public dynamic GetAnonymousType() { }

Call a method Asynchronously in C#

Samual Sam
Updated on 23-Jun-2020 10:50:01

261 Views

Asynchronous programming in C# is an efficient approach towards activities blocked or access is delayed. If an activity is blocked like this in a synchronous process, then the complete application waits and it takes more time. The application stops responding. Using asynchronous approach, the applications continues with other tasks as well.An application with a GUI, check the content of the queue and if an unprocessed task is there, it takes it out and processes it first. The code executes synchronously and the unprocessed task is completed first. The application will show stop responding messages if the processing takes more time ... Read More

DivideByZeroException Class in C#

George John
Updated on 23-Jun-2020 11:04:53

949 Views

C# exceptions are represented by classes. The exception classes in C# are mainly directly or indirectly derived from the System.Exception class. Some of the exception classes derived from the System.Exception class are the System.ApplicationException and System.SystemException classes.System.DivideByZeroException is a class that handles errors generated from dividing a dividend with zero.Example Live Demousing System; namespace ErrorHandlingApplication {    class DivNumbers {       int result;       DivNumbers() {          result = 0;       }       public void division(int num1, int num2) {          try {         ... Read More

Advertisements