Difference Between Type Conversion and Type Casting in C#

karthikeya Boyini
Updated on 20-Jun-2020 15:59:33

500 Views

Type conversion and type casting are the same in C#. It is converting one type of data to another type. In C#, type casting has two forms −Implicit type conversion − These conversions are performed by C# in a type-safe manner. For example, are conversions from smaller to larger integral types and conversions from derived classes to base classes.Explicit type conversion − These conversions are done explicitly by users using the pre-defined functions. Explicit conversions require a cast operator.The following is an example showing how to cast double to int −Example Live Demousing System; namespace Demo {    class Program { ... Read More

What is Serialization in C# .NET

Samual Sam
Updated on 20-Jun-2020 15:58:25

733 Views

Serialization converts objects into a byte stream and brings it to a form that it can be written on stream. This is done to save it to memory, file or database.Serialization can be performed as −Binary SerializationAll the members, even members that are read-only, are serialized.XML SerializationIt serializes the public fields and properties of an object into XML stream conforming to a specific XML Schema definition language document.Let us see an example. Firstly set the stream −FileStream fstream = new FileStream("d:ew.txt", FileMode.OpenOrCreate); BinaryFormatter formatter=new BinaryFormatter();Now create an object of the class and call the constructor which has three parameters −Employee ... Read More

Check If a String Contains a Substring in jQuery

Kristi Castro
Updated on 20-Jun-2020 15:56:41

3K+ Views

The jQuery :contains() Selector is used to check whether a string contains a substring in jQuery.Set the substring you are searching for in the contains() method as shown below:$(document).ready(function(){    $("p:contains(Video)").css("background-color", "blue"); });Now, let us see the complete code to check whether a string contains a substring or not:Example Live Demo               $(document).ready(function(){          $("p:contains(Video)").css("background-color", "blue");       });     Tutorialspoint This is demo text. Free Tutorials Free Video Tutorials

What is Compile-Time Polymorphism in C#

Samual Sam
Updated on 20-Jun-2020 15:55:55

2K+ Views

Polymorphism can be static or dynamic. In static polymorphism, the response to a function is determined at the compile time. In dynamic polymorphism, it is decided at run-time.The linking of a function with an object during compile time is called early binding. It is also called static binding. C# provides two techniques to implement static polymorphism. They are Function overloading and Operator overloading.In function overloading you can have multiple definitions for the same function name in the same scope. The definition of the function must differ from each other by the types and/or the number of arguments in the argument ... Read More

What is a Ternary Operator in C#

Ankith Reddy
Updated on 20-Jun-2020 15:55:02

441 Views

Ternary operator is a Conditional operator in C#. It takes three arguments and evaluates a Boolean expression.For example −y = (x == 1) ? 70 : 100;Above, if the first operand evaluates to true (1), the second operand is evaluated. If the first operand evaluates to false (0), the third operand is evaluated.The following is an example −Example Live Demousing System; namespace DEMO {    class Program {       static void Main(string[] args) {          int a, b;          a = 10;          b = (a == 1) ? 20 : 30;          Console.WriteLine("Value of b is {0}", b);          b = (a == 10) ? 20 : 30;          Console.WriteLine("Value of b is {0}", b);          Console.ReadLine();       }    } }OutputValue of b is 30 Value of b is 20

What is Composition in C#

Arjun Thakur
Updated on 20-Jun-2020 15:54:17

595 Views

If the parent object is deleted under Composition, 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.public class Engine {    . . . } public class Car {       Engine eng = new Engine();       ....... }

What is Default Constructor in C# Programs

karthikeya Boyini
Updated on 20-Jun-2020 15:52:54

809 Views

A Constructor in C# is invoked automatically when an object gets created. The constructor has the same name as that of the class, for example, −public class Department {    public Department () {       Console.WriteLine("Default Constructor! ");    } }The following is the code that shows the usage of default constructor in C#. The constructor invokes immediately when the object gets created −Department dept1 = new Department ();A default constructor is a constructor that has no argument, for example −Department () { }Let us see the complete example to learn how to work with default constructors −Example Live ... Read More

What is a Parameterized Constructor in C++

Chandu yadav
Updated on 20-Jun-2020 15:52:22

3K+ Views

In a constructor you can also add parameters. Such constructors are called parameterized constructors. This technique helps you to assign initial value to an object at the time of its creation.The following is an example −// class class DemoParameterized constructor with a prarameter rank −public Demo(int rank) { Console.WriteLine("RANK = {0}", rank); }Here is the complete example displaying how to work with parameterized constructor in C# −Example Live Demousing System; namespace Demo {    class Line {       private double length; // Length of a line             public Line(double len) { //Parameterized constructor ... Read More

What is Late Binding in C#

Samual Sam
Updated on 20-Jun-2020 15:48:03

1K+ Views

In static polymorphism, the response to a function is determined at the compile time. In dynamic polymorphism, it is decided at run-time. Dynamic polymorphism is what we call late binding.Dynamic polymorphism is implemented by abstract classes and virtual functions. The following is an example showing an example of dynamic polymorphism −Example Live Demousing System; namespace PolymorphismApplication {    class Shape {       protected int width, height;       public Shape( int a = 0, int b = 0) {          width = a;          height = b;       ... Read More

Make Textarea and Input Type Read-Only using jQuery

Kristi Castro
Updated on 20-Jun-2020 15:45:47

3K+ Views

To make a textarea and input type read only, use the attr() method .For readonly, set the input type text and textarea as read only as shown below:$('input[type="text"], textarea').each(function(){    $(this).attr('readonly','readonly'); });The following is the code to set readonly to textarea and input type:Example Live Demo jQuery Example               $(document).ready(function() {          $('input[type="text"], textarea').each(function(){             $(this).attr('readonly','readonly');          });       });     readonly textarea

Advertisements