Found 27759 Articles for Server Side Programming

What is the IsReadOnly property of ArrayList class in C#?

karthikeya Boyini
Updated on 23-Jun-2020 11:48:23

70 Views

The IsReadOnly property of ArrayList class is useful to get a value indicating whether the ArrayList is read-only.Firstly, we have the following ArrayList.ArrayList arrList = new ArrayList();Then we have checked using the IsReadOnly Property.Console.WriteLine("myArrayList.IsReadOnly = " + arrList.IsReadOnly);The following is an example showing how to work with IsReadOnly property in ArrayList class.Example Live Demousing System; using System.Collections; class Demo {    public static void Main() {       ArrayList arrList = new ArrayList();       Console.WriteLine("myArrayList.IsReadOnly = " + arrList.IsReadOnly);    } }OutputmyArrayList.IsReadOnly = False

C# program to check whether a list is empty or not

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

8K+ Views

Use lists in C# to store elements and fetch it. Let us see an example.Example Live Demousing System; using System.Collections.Generic; public class Demo {    public static void Main(string[] args) {       var subjects = new List();       subjects.Add("Maths");       subjects.Add("Java");       subjects.Add("English");       subjects.Add("Science");       subjects.Add("Physics");       subjects.Add("Chemistry");       foreach (var sub in subjects) {          Console.WriteLine(sub);       }    } }OutputMaths Java English Science Physics ChemistryNow to check whether a list is empty or not, use the Count ... Read More

What is the IsFixedSize property of ArrayList class in C#?

Samual Sam
Updated on 23-Jun-2020 11:48:55

85 Views

The IsFixedSize property of ArrayList class is used to get a value indicating whether the ArrayList has a fixed size.The following is an example stating the usage of isFixedSize property.Example Live Demousing System; using System.Collections; class Demo {    public static void Main() {       ArrayList arrList = new ArrayList();       Console.WriteLine("Adding some numbers:");       arrList.Add(45);       arrList.Add(78);       Console.WriteLine(arrList.Count);       Console.WriteLine("myArrayList.IsFixedSize = " + arrList.IsFixedSize);    } }OutputAdding some numbers: 2 myArrayList.IsFixedSize = FalseAbove we have added an array list.ArrayList arrList = new ArrayList();Then we have checked whether ... Read More

What is the Hashtable class in C#?

George John
Updated on 23-Jun-2020 11:50:07

84 Views

Hashtable class represents a collection of key-and-value pairs that are organized based on the hash code of the key. It uses the key to access the elements in the collection.Some of the commonly used methods in Hashtable class are −Sr.No.Method & Description1public virtual void Add(object key, object value);Adds an element with the specified key and value into the Hashtable.2public virtual void Clear();Removes all elements from the Hashtable.3public virtual bool ContainsKey(object key);Determines whether the Hashtable contains a specific key.4public virtual bool ContainsValue(object value);Determines whether the Hashtable contains a specific value.The following is an example showing the usage of Hashtable class in ... Read More

What is the scope resolution operator in C#?

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

841 Views

The scope resolution operator in C# has a different meaning as compared with C++. In C++ the :: is used for global variables, whereas in C# it is related to namespaces.If you have a type that share an identifier in different namespace, then to identify them use the scope resolution operator.For example, to reference System.Console class, use the global namespace alias with the scope resolution operator.global::System.ConsoleExample Live Demousing myAlias = System.Collections; namespace Program {    class Demo {       static void Main() {          myAlias::Hashtable h = new myAlias::Hashtable();          h.Add("Q", "1");   ... Read More

What is the scope of a protected member variable of a class in C#?

Ankith Reddy
Updated on 23-Jun-2020 11:36:24

321 Views

Protected access specifier allows a child class to access the member variables and member functions of its base class. This way it helps in implementing inheritance. We will discuss this in more details in the inheritance chapter.The following is an example showing we have set an protected member variable in Class A.class A {    protected int a2 = 87; }Now under the derived class when we will try to access the above variable from the derived class object, then it would work fine as shown below −Exampleusing System; class A {    protected int a2 = 87; } class ... Read More

Difference between C# and Visual C#

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

1K+ Views

C# and Visual C# are both the same. When you use Visual Studio for C# development, it is called Visual C# .Consider Visual C# as an implementation of C#. Microsoft Visual Studio is an IDE from Microsoft to develop programs, web app, web services, etc. The current version of Visual Studio is Visual Studio 2017, that supports .NET 3.5 to 4.7 framework. C# is a multi-paradigm programming language whose current version is C# 7.3. The following reasons make C# a widely used professional language − It is a modern, general-purpose programming language It is object oriented. It is ... Read More

How to find minimum between 2 numbers using C#?

Samual Sam
Updated on 23-Jun-2020 11:37:27

2K+ Views

Firstly, declare and initialize two numbers.int num1 = 35; int num2 = 55;With that, use if- else to find the minimum number.if (num1 < num2) {    minNum = num1; } else {    minNum = num2; }Above, we have set the minimum value to the variable minNum and printed it later on.The following is the complete example to find minimum 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

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

karthikeya Boyini
Updated on 23-Jun-2020 11:38:52

49 Views

A sorted list is a combination of an array and a hash table. It contains a list of items that can be accessed using a key or an index.Gets and sets the value associated with a specific key in the SortedList.You can also use the Item property to add new elements.If a key does not exist, then you can include it like.myCollection["myNonexistentKey"] = myValueIf the key already exist, then it will overwrite it with the new key and value.The following is an example to learn how to work with Item property of SorteList class in C#.Example Live Demousing System; using System.Collections; ... Read More

What is the scope of a protected internal member variable of a class in C#?

Chandu yadav
Updated on 23-Jun-2020 11:38:17

240 Views

The protected internal access specifier allows a class to hide its member variables and member functions from other class objects and functions, except a child class within the same application.In the below example, the derived class object can access the protected internal variable.Example Live Demousing System; class One {    protected internal int a = 50;    private int b; } class Two : One {    public Two() {       Console.WriteLine(this.a);    } } class Demo {    static void Main() {       Two t = new Two();       // allowed since it is a derived class object       t.a = 20;    } }Output50

Advertisements