Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Write a program in C# to implement conditional operator/ternary operator ?
- namespace ConsoleApp1
- {
- class Program
- {
- static void Main(string[] args)
- {
- int x = 20, y = 10;
- var result = x > y ? "x is greater than y" : "x is less than y";
- Console.WriteLine(result);
- }
- }
- }
- Write a program in C# to illustrate Operator Overloading.
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace During_Vacation
- {
- internal class UnaryOpOv
- {
- int a;
- int b;
- public UnaryOpOv()
- {
- }
- public UnaryOpOv(int x, int y)
- {
- a = x;
- b = y;
- }
- public void display()
- {
- Console.WriteLine("value of a is: " + a);
- Console.WriteLine("value of b is : " + b);
- }
- public static UnaryOpOv operator -(UnaryOpOv m)
- {
- UnaryOpOv myun = new UnaryOpOv();
- myun.a = -m.a;
- myun.b=-m.b;
- return myun;
- }
- }
- public class mainclass
- {
- public static void Main(string[] args)
- {
- UnaryOpOv m1 = new UnaryOpOv(2, 3);
- m1.display();
- UnaryOpOv m2 = new UnaryOpOv(4,5);
- m2.display();
- m2 = -m1;
- m2.display();
- }
- }
- }
- Write a program in C# to illustrate generics.
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Runtime.InteropServices;
- using System.Text;
- using System.Threading.Tasks;
- namespace Practice_in__class
- {
- public class Mygeneric<T>
- {
- // private data members
- private T a;
- // using properties
- public T Myproperty
- {
- // using accessors
- get
- {
- return this.a;
- }
- set
- {
- this.a = value;
- }
- }
- }
- internal class Rough_place
- {
- public static void Main(String[] args)
- {
- // instance of string type
- Mygeneric<string> name = new Mygeneric<string>();
- name.Myproperty = "My name is generic";
- // instance of float type
- Mygeneric<float> myvalue = new Mygeneric<float>();
- myvalue.Myproperty = 30.3F;
- Console.WriteLine(name.Myproperty);
- Console.WriteLine(myvalue.Myproperty);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment