What is Boxing in C#

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

532 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

What is C Hash Programming

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

311 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 Cast Operator in C#

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

799 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;

Difference Between Implicit and Explicit Type Conversion in C#

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

948 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

Difference Between Internal and Private Modifiers in C#

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

2K+ 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

Generating OTP in Java

Fendadis John
Updated on 21-Jun-2020 15:00:56

5K+ Views

Generate OTP is now a requirement on most of the website now-a-days. In case of additional authentication, system generates a OTP password adhering to OTP policy of the company. Following example generates a unique OTP adhering to following conditions −It should contain at least one number.Length should be 4 characters.Exampleimport java.util.Random; public class Tester {    public static void main(String[] args) {       System.out.println(generateOTP(4));    }    private static char[] generateOTP(int length) {       String numbers = "1234567890";       Random random = new Random();       char[] otp = new ... Read More

Index-Based I/O in ArrayList Collection in C#

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

487 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

Add Integer Values to a Chash List

Samual Sam
Updated on 21-Jun-2020 14:58:47

9K+ Views

To add integer values to a list in C#, use the Add() method.Firstly, declare an integer list in C# −List list1 = new List();Now add integer values −list1.Add(900); list1.Add(400); list1.Add(300);Let us see the complete code −Exampleusing System; using System.Collections.Generic; using System.Linq; using System.Text.RegularExpressions; namespace Demo {    public class Program {       public static void Main(String[] args) {          List list1 = new List();          list1.Add(900);          list1.Add(400);          list1.Add(300);          Console.WriteLine(list1.Count);       }    } }

Add Items to a List in C#

Arjun Thakur
Updated on 21-Jun-2020 14:58:17

938 Views

Firstly, declare a list −var teams = new List();To add items to a C# list, use the Add() method −teams.Add("US"); teams.Add("Canada"); teams.Add("India"); teams.Add("Australia");You can try to run the following code to add items to a list in C# −Exampleusing System; using System.Collections.Generic; public class Demo {    public static void Main(string[] args) {       var teams = new List();       teams.Add("US");       teams.Add("Canada");       teams.Add("India");       teams.Add("Australia");           Console.WriteLine("Elements...");       foreach (var countries in teams) {          Console.WriteLine(countries);       }    } }

Flow Control in a Try-Catch-Finally in Java

Vikyath Ram
Updated on 21-Jun-2020 14:57:44

7K+ Views

A method catches an exception using a combination of the try and catch keywords. A try/catch block is placed around the code that might generate an exception. Code within a try/catch block is referred to as protected code, and the syntax for using try/catch looks like the following −Syntaxtry {    // Protected code } catch (ExceptionName e1) {    // Catch block }The code which is prone to exceptions is placed in the try block. When an exception occurs, that exception occurred is handled by catch block associated with it. Every try block should be immediately followed either by ... Read More

Advertisements