Q:

Write a program in C# Sharp to demonstrates structure initialization without using the new operator

0

Write a program in C# Sharp to demonstrates structure initialization without using the new operator.

Expected Output :

Structure initialization without using the new operator :                    
--------------------------------------------------------                
newStruct : m = 30, n = 40

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 strucExer8
{
    static void Main()
    {
	Console.Write("\n\nStructure initialization without using the new operator :\n");
	Console.Write("----------------------------------------------------------\n");
        newStruct myPoint;
        myPoint.m = 30;
        myPoint.n = 40;
        Console.Write("\nnewStruct : ");
        Console.WriteLine("m = {0}, n = {1}", myPoint.m, myPoint.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