The abstract keyword in C# is used for abstract classes. An abstract class in C# includes abstract and nonabstract methods. You cannot instantiate an abstract class.Example of an abstract class Vehicle and abstract method display() −public abstract class Vehicle { public abstract void display(); }The abstract class has derived classes: Bus, Car, and Motorcycle. The following is an implementation of the Car derived class −public class Car : Vehicle { public override void display() { Console.WriteLine("Car"); } }ExampleThe following is an example of abstract classes in C# −Live Demousing System; public abstract class Vehicle ... Read More
To add and concatenate strings in C#, use the string. Concat method. The plus operator can also be used for the same purpose of concatenation.Plus Operatorstring str2 = "Hanks" + str1;ExampleLet us see an example of + operator to concatenate strings −Live Demousing System; class Program { static void Main() { string str1 = "Tom"; // concatenation string str2 = "Hanks" + str1; Console.WriteLine(str2); } }OutputHanksTomString.concatstring str2 = string.Concat("Hanks", str1);ExampleLet us see an example of string.concat to concatenate strings in C# −Live Demousing ... Read More
The abstract class includes abstract and non-abstract methods. You cannot instantiate an abstract class.The sealed class prevents inheritance and you cannot use it as a base class.Abstract ClassesTo declare an abstract class, you need to place the keyword abstract before the class definition. An example of class members in an abstract class can be the following that defines an abstract method −public abstract class Vehicle { public abstract void display(); }The abstract method definition is followed by a semi-colon since it has no implementation.Sealed ClassesTo declare a sealed class, you need to place the keyword sealed before the class definition. ... Read More
To calculate a factorial in C#, you can use any of the following three ways −Calculate factorial with for loopExampleLive Demousing System; using System.Collections.Generic; using System.Linq; using System.Text; namespace factorial { class Test { static void Main(string[] args) { int i, res; int value = 5; res = value; for (i = value - 1; i >= 1; i--) { res = res * i; } ... Read More
Association in C#The association defines the relationship between an object in C#. An a one-to-one, one-to-many, many-to-one and many-to-many relationship can be defined between objects.For example, An Employee can be associated with multiple projects, whereas a project can have more than one employee.Composition in C#Under Composition, if the parent object is deleted, then the child object also loses its status.The composition is a special type of Aggregation and gives a part-of relationship.For example, A Car has an engine. If the car is destroyed, the engine is destroyed as well.Aggregation in C#Aggregation is a direct relation between objects in C#. It ... Read More
GeneralizationGeneralization is a process of generalizing an entity which contains generalized attributes or properties of generalized entities. The entity that is created will contain the common features. Generalization is a Bottom up process.We can have three sub entities as Car, Truck, Motorcycle and these three entities can be generalized into one general super class as Vehicle.It is a form of abstraction that specifies two or more entities (sub class) having common characters that can be generalized into one single entity (super class) at higher level hiding all the differences.SpecializationSpecialization is a process of identifying subsets of an entity that shares ... Read More
To get the sine of a number, use the JavaScript sine() technique. The sin technique returns a numeric value between -1 and one, that represents the sine of the argumentExampleYou can try to run the following code to get the sine of a number in JavaScript − JavaScript Math sin() Method var value = Math.sin( 0.5 ); document.write("First Value : " + value ); var value = Math.sin( 90 ); document.write("Second Value : " + value );
To get a pseudo-random number between 0 and 1, use the Math.random() method in JavaScript.ExampleYou can try to run the following code to get a pseudo-random number between 0 and 1 − JavaScript Math random() Method var value = Math.random( ); document.write("First Value : " + value ); value = Math.random( ); document.write("Second Value : " + value );
The following is a simple “Hello World” program in C# programming −ExampleLive Demousing System; namespace MyHelloWorldApplication { class MyDemoClass { static void Main(string[] args) { // display text Console.WriteLine("Hello World"); // display another text Console.WriteLine("Welcome!"); Console.ReadKey(); } } }OutputHello World Welcome!Let us see now what all it includes −using System − the using keyword is used to include the System namespace in the program.namespace declaration − A namespace is a collection of classes. The ... Read More
A resizable implementation of the List interface is called ArrayList. It is a non-generic type of collection in C# that dynamically resizes.Let us see how to initialize ArrayList in C# −ArrayList arr= new ArrayList();Add an element like the below-given code snippet −ArrayList arr1 = new ArrayList(); arr1.Add(120); arr1.Add(160);Let us see the complete example to implement ArrayList in C# −ExampleLive Demousing System; using System.Collections; public class MyClass { public static void Main() { ArrayList arr1 = new ArrayList(); arr1.Add(120); arr1.Add(160); ArrayList arr2 = new ArrayList(); ... Read More
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP