Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
Dotnetq5
//WAP to show the use of Constructor & destructor //Rextester.Program.Main is the entry point for your code. Don't change it. //Compiler version 4.0.30319.17929 for Microsoft (R) .NET Framework 4.5 using System; using System.Collections.Generic; using System.Linq; using System.Text.RegularExpressions; namespace Rextester { class Complex { // Class members, private // by default int real, img; // Defining the constructor public Complex() { real = 0; img = 0; } // SetValue method sets // value of real and img public void SetValue(int r, int i) { real = r; img = i; } // DisplayValue displays // values of real and img public void DisplayValue() { Console.WriteLine("Real = " + real); Console.WriteLine("Imaginary = " + img); } // Defining the destructor // for class Complex ~Complex() { Console.WriteLine("Destructor was called"); } } // End class Complex public class Program { public static void Main(string[] args) { // Creating an instance of class // Complex C invokes constructor Complex C = new Complex(); // Calling SetValue method using // instance C Setting values of // real to 2 and img to 3 C.SetValue(2, 3); // Displaying values of real // and imaginary parts C.DisplayValue(); // Instance is no longer needed // Destructor will be called } } }
run
|
edit
|
history
|
help
0
IotaSeedGenerator
Root
dima
Talk To Jack
Print dulicate chars in a string
Prsonal informashin
Huffman Algorithm
5
pattern
Hello