Articles on Trending Technologies

Technical articles with clear explanations and examples

What are the differences between a static and a non-static class in C#?

Arjun Thakur
Arjun Thakur
Updated on 21-Jun-2020 2K+ Views

The following is the difference between a static and non-static class −Non-static classes can be instantiated, whereas static classes cannot be instantiated i.e. you cannot use the new keyword to create a variable of the class typeStatic classes can only have static methods.Non-static classes can have instance method and static methods.ou access the members of a static class by using the class name itselfStatic class is sealed.Example of static class −public static class CalculateExample of non-static class −public class Calculate

Read More

How to copy or clone a C# list?

Samual Sam
Samual Sam
Updated on 21-Jun-2020 3K+ 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

What is boxing in C#?

George John
George John
Updated on 21-Jun-2020 572 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# Programming?

karthikeya Boyini
karthikeya Boyini
Updated on 21-Jun-2020 343 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

Read More

What is Cast Operator () in C#?

Ankith Reddy
Ankith Reddy
Updated on 21-Jun-2020 843 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;

Read More

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

Samual Sam
Samual Sam
Updated on 21-Jun-2020 1K+ 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
Arjun Thakur
Updated on 21-Jun-2020 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
Fendadis John
Updated on 21-Jun-2020 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

How to add integer values to a C# list?

Samual Sam
Samual Sam
Updated on 21-Jun-2020 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);       }    } }

Read More

How to add items to a list in C#?

Arjun Thakur
Arjun Thakur
Updated on 21-Jun-2020 982 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);       }    } }

Read More
Showing 49261–49270 of 61,248 articles
Advertisements