Found 27759 Articles for Server Side Programming

How to create an infinite loop in C#?

Arjun Thakur
Updated on 23-Jun-2020 12:10:34

1K+ Views

An infinite loop is a loop that never terminates and repeats indefinitely.Let us see an example to create an infinite loop in C#.Exampleusing System; namespace Demo {    class Program {       static void Main(string[] args) {          for (int a = 0; a < 50; a--) {             Console.WriteLine("value : {0}", a);          }          Console.ReadLine();       }    } }Above, the loop executes until a < 50. The value of is set to 0 initially.int a = 0;The value of a decrements after each iteration since it is set to.a--;Therefore the value of a will never be above 50 and the condition a

How to create arrays dynamically in C#?

Samual Sam
Updated on 23-Jun-2020 12:10:04

4K+ Views

Dynamic arrays are growable arrays and have an advantage over static arrays. This is because the size of an array is fixed.To create arrays dynamically in C#, use the ArrayList collection. It represents ordered collection of an object that can be indexed individually. It also allows dynamic memory allocation, adding, searching and sorting items in the list.The following is an example showing how to create arrays in dynamically in C#.Example Live Demousing System; using System.Collections; namespace CollectionApplication {    class Program {       static void Main(string[] args) {          ArrayList al = new ArrayList();     ... Read More

How to create a thread in C#?

Chandu yadav
Updated on 23-Jun-2020 12:11:59

491 Views

Threads are lightweight processes. A thread is defined as the execution path of a program. Threads are created by extending the Thread class. The extended Thread class then calls the Start() method to begin the child thread execution.Example of Thread: One common example of use of thread is implementation of concurrent programming by modern operating systems. Use of threads saves wastage of CPU cycle and increase efficiency of an application.The following is an example showing how to create a thread.Example Live Demousing System; using System.Threading; namespace Demo {    class Program {       public static void ThreadFunc() {   ... Read More

How to create a tuple with string and int items in C#?

karthikeya Boyini
Updated on 23-Jun-2020 12:11:10

246 Views

Firstly, set two items in the tuple.Tuple tuple = new Tuple(20, "Tom");Now check for first item in the tuple, which is an integer.if (tuple.Item1 == 20) {    Console.WriteLine(tuple.Item1); }Now check for second item in the tuple, which is a string −if (tuple.Item2 == "Tom") {    Console.WriteLine(tuple.Item2); }The following is an example to create a tuple with string and int items.Example Live Demousing System; using System.Threading; namespace Demo {    class Program {       static void Main(string[] args) {          Tuple tuple = new Tuple(20, "Tom");          if (tuple.Item1 == 20) { ... Read More

How to create a String object in C#?

Samual Sam
Updated on 23-Jun-2020 11:45:14

3K+ Views

To create a string object in C#, use any of the below given method.By assigning a string literal to a String variableBy using a String class constructorBy using the string concatenation operator (+)By retrieving a property or calling a method that returns a stringBy calling a formatting method to convert a value or an object to its string representationThe following is an example showing different ways to create a string object in C#.Example Live Demousing System; namespace Demo {    class Program {       static void Main(string[] args) {          //from string literal and string concatenation ... Read More

How to find maximum between 2 numbers using C#?

George John
Updated on 23-Jun-2020 12:12:53

1K+ Views

Firstly, declare and initialize two numbers.int num1 = 50; int num2 = 90;With that, use if-else to find the maximum number.if (num1 > num2) {    maxNum = num1; } else {    maxNum = num2; }Above, we have set the maximum value to the variable maxNum and printed it later on.The following is the complete example to find maximum between 2 numbers in C#.Example Live Demousing System; namespace Demo {    class Program {       static void Main(string[] args) {          int num1 = 50;          int num2 = 90;     ... Read More

How to initialize an array in C#?

Ankith Reddy
Updated on 30-Jul-2019 22:30:23

2K+ Views

All arrays consist of contiguous memory locations. The lowest address corresponds to the first element and the highest address to the last element. Firstly, declare an array. int[] rank; But declaring an array does not initialize the array in the memory. When the array variable is initialized, you can assign values to the array. Array is a reference type, so you need to use the new keyword to create an instance of the array. For example, int[] rank = new int[5]; You can assign values to an array at the time of declaration. int[] rank ... Read More

How to Initialize and Compare Strings in C#?

karthikeya Boyini
Updated on 23-Jun-2020 11:45:50

150 Views

To initializes a string in C# is an easy task. Let’s say you want to set a name “Amit”, for that, initialize your string as.String str1 = "Hello, World!";To compare strings, use the the following C# method.public static int Compare(string str1, string str2)To compare, if −String.Compare(str1, str2) == 0If the above is equal to 0, then both the strings are equal.The above method compares two specified string objects and returns an integer that indicates their relative position in the sort order.The following is an example that shows the comparison of one string to another.Example Live Demousing System; namespace Demo {   ... Read More

Explain C# Substitution in regular expression

Arjun Thakur
Updated on 30-Jul-2019 22:30:23

136 Views

A regular expression is a pattern that could be matched against an input text. There are various categories of characters, operators, and constructs that let’s you to define regular expressions. Substitutions are used in replacement patterns. The following table lists the substitutions. Character Description Pattern Replacement pattern Input string Resulting string $number Substitutes the substring matched by group number. \b(\w+)(\s)(\w+)\b $3$2$1 "one two" "two one" ${name} Substitutes the substring matched by the named groupname. \b(?< word1>\w+)(\s)(?< word2>\w+)\b ${word2} ${word1} "one two" "two one" ... Read More

What is the Length property of BitArray class in C#?

Samual Sam
Updated on 23-Jun-2020 11:47:02

55 Views

The length property is used to gets or sets the number of elements in the BitArray.Our BitArray.BitArray arr = new BitArray( 5 );To calculate the length, use the length property.Console.WriteLine( "Length: {0}", arr.Length );You can try to run the following code to learn how to work with Length property of BitArray class.Example Live Demousing System; using System.Collections; public class Demo {    public static void Main() {       BitArray arr = new BitArray( 5 );       Console.WriteLine( "Count: {0}", arr.Count );       Console.WriteLine( "Length: {0}", arr.Length );    } }OutputCount: 5 Length: 5

Advertisements