Code Monkey home page Code Monkey logo

operator-overloading's Introduction

EX-6 Operator-Overloading

Date:

Aim:

To write a C# program to pass values through constructors(default and parameterized) and also overload equal operators by checking whether objects are equal using operator overloading.

Algorithm:

Step 1:

Create a class operator

Step 2:

Pass values through the constructor

Step 3:

return the bool operator, (==) and (!=)

Step 4:

create a object to store the return object

Step 5:

print the program.

Program:

NAME : SWATHIKA G
REG NO : 212221230113

using System;
namespace overload
{
   class example
   {
       int n;
       public example(int a)
       {
           this.n = a;
           Console.Write("This is default Constructor");
           Console.WriteLine(" value is = " + this.n);
       }
       public example()
       {
           this.n = 10;
           Console.WriteLine("Default Constructor value is = " + this.n);
       }
       public static bool operator ==(example e1, example e2)
       {
           return e1.Equals(e2);
       }
       public static bool operator !=(example e1, example e2)
       {
           return !e1.Equals(e2);
       }
       static void Main(string[] args)
       {
           example e1 = new example(10);
           example e4 = new example();
           example e2 = e4;
           if (e2 == e4)
           {
               Console.WriteLine("Both are equal");
           }
           else
           {
               Console.WriteLine("Both are not equal");
           }
       }
   }
}

Output:

exp6

Result:

Thus the C# program to find the volume of a box using operator overloading is implemented successfully.

operator-overloading's People

Contributors

archanasharikalharinarayanan avatar swathika28 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.