Q:

Write a program in C# Sharp to demonstrates structure initialization using both default and parameterized constructors

0

Write a program in C# Sharp to demonstrates structure initialization using both default and parameterized constructors.

Expected Output:

Structure declares using default and parameterized constructors :                    
-----------------------------------------------------------------                
newStruct 1: m = 0, n = 0                                                        
newStruct 2: m = 25, n = 25  

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

using System;
public struct newStruct
{
    public int m, n;
    public newStruct(int pt1, int pt2)
    {
        m = pt1;
        n = pt2;
    }
}
// Declare and initialize struct objects.
class strucExer7
{
    static void Main()
    {
		Console.Write("\n\nStructure declares using default and parameterized constructors :\n");
		Console.Write("-----------------------------------------------------------------\n");
        newStruct myPoint1 = new newStruct();
        newStruct myPoint2 = new newStruct(25, 25);
        Console.Write("\nnewStruct 1: ");
        Console.WriteLine("m = {0}, n = {1}", myPoint1.m, myPoint1.n);
        Console.Write("newStruct 2: ");
        Console.WriteLine("m = {0}, n = {1}", myPoint2.m, myPoint2.n);
        Console.WriteLine("\nPress any key to exit.");
        Console.ReadKey();
    }
}

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Similar questions


need a help?


find thousands of online teachers now