Found 2628 Articles for Csharp

What is the default access for a class member in C#?

George John
Updated on 21-Jun-2020 15:18:21

2K+ Views

The default access for a class member in C# is private.Member variables i.e. class members are the attributes of an object (from design perspective) and they are kept private to implement encapsulation. These variables can only be accessed using the public member functions.Exampleusing System; namespace RectangleApplication {    class Rectangle {       //member variables       private double length;       private double width;       public void Acceptdetails() {          length = 10;          width = 14;       }       public ... Read More

Final local variables in C#

Samual Sam
Updated on 21-Jun-2020 15:19:47

1K+ Views

To set final for a local variable, use the read-only keyword in C#, since the implementation of the final keyword is not possible.The readonly would allow the variables to be assigned a value only once. A field marked "read-only", can only be set once during the construction of an object. It cannot be changed.Let us see an example. Below, we have set the empCount field as read-only, which once assigned cannot be changed.Exampleclass Department {    readonly int empCount;    Employee(int empCount) {       this. empCount = empCount;    }    void ChangeCount() {       //empCount = 150; // Compile error    } }

What is index-based I/O BitArray collection in C#?

Chandu yadav
Updated on 21-Jun-2020 15:21:05

108 Views

The BitArray class manages a compact array of bit values, which are represented as Booleans, where true indicates that the bit is on (1) and false indicates the bit is off (0).The following are the method of the index-based BitArray collection −Sr.No.Method & Description1public BitArray And(BitArray value);Performs the bitwise AND operation on the elements in the current BitArray against the corresponding elements in the specified BitArray.2public bool Get(int index);Gets the value of the bit at a specific position in the BitArray.3public BitArray Not();Inverts all the bit values in the current BitArray, so that elements set to true are changed to ... Read More

What is index-based I/O ArrayList collection in C#?

karthikeya Boyini
Updated on 21-Jun-2020 14:59:39

303 Views

ArrayList class represents an ordered collection of an object that can be indexed individually. It is an alternative to an array.The following table lists some of the commonly used properties of the ArrayList class −Sr.NoProperty & Description1CapacityGets or sets the number of elements that the ArrayList can contain.2CountGets the number of elements actually contained in the ArrayList.3IsFixedSizeGets a value indicating whether the ArrayList has a fixed size.4IsReadOnlyGets a value indicating whether the ArrayList is read-only.5ItemGets or sets the element at the specified index.The following is an example showing how to work with ArrayList in C# and finding the capacity. The ... Read More

What is the difference between implicit and explicit type conversion in C#?

Samual Sam
Updated on 21-Jun-2020 15:03:14

737 Views

The following is the difference between implicit and explicit type conversion −Implicit Type ConversionThese conversions are performed by C# in a type-safe manner.To understand the concept, let us implicitly convert int to long.int val1 = 11000; int val2 = 35600; long sum; sum = val1 + val2;Above, we have two integer variable and when we sum it in a long variable, it won’t show an error. Since the compiler does the implicit conversion on its own.Let us print the values now.Exampleusing System; using System.IO; namespace Demo {    class Program {       static void Main(string[] args) ... Read More

What is difference between internal and private modifiers in C#?

Arjun Thakur
Updated on 21-Jun-2020 15:02:21

1K+ Views

Internal Access SpecifierInternal access specifier allows a class to expose its member variables and member functions to other functions and objects in the current assembly.Any member with internal access specifier can be accessed from any class or method defined within the application in which the member is defined.The following is an example −Exampleusing System; namespace RectangleApplication {    class Rectangle {       //member variables       internal double length;       internal double width;       double GetArea() {          return length * width;       }   ... Read More

What is Cast Operator () in C#?

Ankith Reddy
Updated on 21-Jun-2020 15:03:46

584 Views

Type conversion is converting one type of data to another type. Explicit conversions are done explicitly by users using the pre-defined functions and require a cast operator.Let us see an example to cast double to int −Exampleusing System; namespace Demo {    class Program {       static void Main(string[] args) {          double a = 4563.56;          int x;          x = (int)a;          Console.WriteLine(x);          Console.ReadKey();       }    } }To cast double to int, we perfomed explicit type casting −x = (int)a;

What is C# Programming?

karthikeya Boyini
Updated on 21-Jun-2020 15:04:37

167 Views

C# is a modern, general-purpose, object-oriented programming language developed by Microsoft.C# is designed for Common Language Infrastructure (CLI), which consists of the executable code and runtime environment that allows the use of various high-level languages on different computer platforms and architectures.Here are the features of C# −Boolean ConditionsAutomatic Garbage CollectionStandard LibraryAssembly VersioningProperties and EventsDelegates and Events ManagementEasy-to-use GenericsIndexersConditional CompilationSimple MultithreadingLINQ and Lambda ExpressionsIntegration with Windows

What is boxing in C#?

George John
Updated on 21-Jun-2020 15:05:29

423 Views

Boxing convert value type to an object type. Let us see an example of boxing −int x = 50; object ob = x; // boxingIn boxing, the value stored on the stack is copied to the object stored on heap memory, whereas unboxing is the opposite.Boxing is useful in storing value types in the garbage-collected heap. It is implicit conversion of a value type to the type object.Let us see an example −Exampleusing System; using System.Collections.Generic; using System.Linq; public class Demo {    static void Main() {       int x = 50;       object ... Read More

How to copy or clone a C# list?

Samual Sam
Updated on 21-Jun-2020 15:06:41

2K+ Views

To copy or clone a C# list, firstly set a list −List < string > list1 = new List < string > (); list1.Add("One"); list1.Add("Two"); list1.Add("Three"); list1.Add("Four");Now declare a string array and use the CopyTo() method to copy.string[] arr = new string[20]; list1.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 > list1 = new List < string > ();       list1.Add("One");       list1.Add("Two");       list1.Add("Three");   ... Read More

Advertisements