Server Side Programming Articles - Page 2531 of 2650

How to assign a reference to a variable in C#

Ankith Reddy
Updated on 20-Jun-2020 10:57:25

6K+ Views

To assign reference to a variable, use the ref keyword. A reference parameter is a reference to a memory location of a variable. When you pass parameters by reference, unlike value parameters, a new storage location is not created for these parameters. Declare the reference parameters using the ref keyword.Let us see an example −Here, we are swapping two values using the ref keyword −Example Live Demousing System; namespace Demo {    class Program {       public void swap(ref int x, ref int y) {          int temp;          temp = ... Read More

C# Program to Implement Stack with Push and Pop operations

Samual Sam
Updated on 20-Jun-2020 10:59:24

740 Views

Set stack with Push operation to add elements to the Stack −Stack st = new Stack(); st.Push('A'); st.Push('M'); st.Push('G'); st.Push('W');To Pop elements from the stack, use Pop() method −st.Pop();st.Pop();The following is an example to implement a stack with Push and Pop operations −Example Live Demousing System; using System.Collections; namespace CollectionsApplication {    class Program {       static void Main(string[] args) {          Stack st = new Stack();          st.Push('A');          st.Push('M');          st.Push('G');          st.Push('W');          Console.WriteLine("Current ... Read More

How is an array initialized in C#?

karthikeya Boyini
Updated on 20-Jun-2020 11:00:30

129 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 = { 1, 2, 3, 4, 5};With that, ... Read More

What are Left Shift and Right Shift Operators (>> and <<) in C#?

George John
Updated on 20-Jun-2020 11:00:02

951 Views

Bitwise Left shift operatorThe left operands value is moved left by the number of bits specified by the right operand.Bitwise Right shift operatorThe left operands value is moved right by the number of bits specified by the right operand.The following is an example showing how to work with Bitwise left and right shift operators −Example Live Demousing System; namespace Demo {    class Program {       static void Main(string[] args) {          int a = 60; /* 60 = 0011 1100 */          int b = 13; /* 13 = 0000 1101 */          int c = 0;          c = a > 2; /* 15 = 0000 1111 */          Console.WriteLine("Value of c is {0}", c);          Console.ReadLine();       }    } }OutputValue of c is 240 Value of c is 15

How is a new object created in C#?

Samual Sam
Updated on 20-Jun-2020 11:01:50

145 Views

Like any other object-oriented language, C# also has object and classes. Objects are real-world entities and instance of a class. Access the members of the class using an object.To access the class members, you need to use the dot (.) operator after the object name. The dot operator links the name of an object with the name of a member, for example, Box Box1 = new Box();Above you can see Box1 is our object. We will use it to access the members −Box1.height = 7.0;You can also use it to call member functions −Box1.getVolume();The following is an example showing how ... Read More

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

Chandu yadav
Updated on 20-Jun-2020 11:02:51

133 Views

Example Live Demousing System; using System.Collections; namespace Demo {    class Program {       static void Main(string[] args) {          SortedList s = new SortedList();          s.Add("S1", "Electronics");          s.Add("S2", "Clothing");          s.Add("S3", "Applicances");          s.Add("S4", "Books");          s.Add("S5", "Accessories");          s.Add("S6", "Musical Instruments");          Console.WriteLine("Count = " + s.Count);       }    } }OutputCount = 6

What is the Count property of Stack class in C#?

karthikeya Boyini
Updated on 20-Jun-2020 11:03:35

252 Views

To find how many elements are added in the Stack class, you need to use the Count property.Let us first add elements in the Stack −Stack st = new Stack(); st.Push('H'); st.Push('I'); st.Push('J'); st.Push('K'); st.Push('L'); st.Push('M'); st.Push('N'); st.Push('O');Now count the number of elements in the Stack −Console.WriteLine("Count: "+st.Count);Let us see the complete code −Example Live Demousing System; using System.Collections; namespace Demo {    class Program {       static void Main(string[] args) {          Stack st = new Stack();          st.Push('H');          st.Push('I');          st.Push('J'); ... Read More

What is the Count property of Queue class in C#?

Samual Sam
Updated on 20-Jun-2020 11:04:13

165 Views

Use the Count property to find the count of elements of the Queue class. Set elements like the following declaration −Queue q = new Queue(); q.Enqueue(1); q.Enqueue(2); q.Enqueue(3); q.Enqueue(4);Then use the Count property to count the elements −q.CountThe following is an example showing how to work with Count property in Queue Class −Example Live Demousing System; using System.Collections; namespace Demo {    class Program {       static void Main(string[] args) {          Queue q = new Queue();          q.Enqueue(1);          q.Enqueue(2);          q.Enqueue(3);          q.Enqueue(4);          Console.WriteLine("Total elements: {0} ", q.Count);              Console.ReadKey();       }    } }OutputTotal elements: 4

What is the Count property of Hashtable class in C#?

Arjun Thakur
Updated on 20-Jun-2020 11:05:04

137 Views

To find the count of elements of Hashtable class, use the Count property. Firstly, set the Hashtable class with elements −Hashtable ht = new Hashtable(); ht.Add("One", "Tom"); ht.Add("Two", "Jack"); ht.Add("Three", "Peter"); ht.Add("Four", "Russel"); ht.Add("Five", "Brad"); ht.Add("Six", "Bradley"); ht.Add("Seven", "Steve"); ht.Add("Eight", "David");Now, count the number of elements using the Count property −ht.CountThe following is the complete example to learn about the usage of Hashtable Count property in C#.Example Live Demousing System; using System.Collections; namespace Demo {    class Program {       static void Main(string[] args) {          Hashtable ht = new Hashtable();     ... Read More

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

karthikeya Boyini
Updated on 20-Jun-2020 11:05:29

137 Views

Count the number of elements in the BitArray class using the Count property.Let us first set our BitArray class −BitArray arr = new BitArray(10);Now use the Count property as shown below −Example Live Demousing System; using System.Collections; public class Demo {    public static void Main() {       BitArray arr = new BitArray(10);       Console.WriteLine( "Count: {0}", arr.Count );    } }OutputCount: 10

Advertisements