What is a Ternary Operator in C#

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

417 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

575 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

784 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

Disable/Enable Checkbox with jQuery

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

6K+ Views

fTo disable and enable checkbox, use the attr() method.Initially set the input type checkbox and disable it −MaleNow on the click of a button, toggle between disabled and enabled checkbox −$("#button1").click(function() {    $("#sName").attr('disabled', !$("#sName").attr('disabled')); });Example Live Demo jQuery Example               $(document).ready(function() {          $("#button1").click(function() {             $("#sName").attr('disabled', !$("#sName").attr('disabled'));          });       });     Male

Pass Parameters to a Method in C#

karthikeya Boyini
Updated on 20-Jun-2020 15:40:16

254 Views

To pass parameters to a method in C#, let us see how to pass parameters by value. In this mechanism, when a method is called, a new storage location is created for each value parameter.The values of the actual parameters are copied into them. Hence, the changes made to the parameter inside the method have no effect on the argument.Here is the example showing how to pass parameters to a method −Example Live Demousing System; namespace Demo {    class NumberManipulator {       public void swap(int x, int y) {          int temp;     ... Read More

Pass Pointers as Parameters to Methods in C#

Samual Sam
Updated on 20-Jun-2020 15:39:11

2K+ Views

To pass pointers as parameters to methods, refer the below steps −Firstly, crate a function swap with unsafe modifier.public unsafe void swap(int* p, int *q) {    int temp = *p;    *p = *q;    *q = temp; }Now under static void main, add the value for the first and second variable, set pointers for both of them.Display the values of the variables and then call the swap() method shown above. The method swaps the values and displays the result −public unsafe static void Main() {    Program p = new Program();    int var1 = 10;    int ... Read More

What are Pointers in C#

Arjun Thakur
Updated on 20-Jun-2020 15:38:39

6K+ Views

Pointer is a variable whose value is the address of another variable i.e., the direct address of the memory location.The syntax of a pointer is −type *var-name;The following is how you can declare a pointer type −double *z; /* pointer to a double */C# allows using pointer variables in a function of code block when it is marked by the unsafe modifier. The unsafe code or the unmanaged code is a code block that uses a pointer variable.The following is our module showing how to declare and use a pointer variable. We have used unsafe modifier here −static unsafe void ... Read More

Advertisements