Write a program in C# Sharp to create a structure and assign the value and call it

  • برمجة سي شارب
  • برمجة

Write a program in C# Sharp to create a structure and assign the value and call it.

Expected Output:

Create a structure and Assign the Value and call it :                            
---------------------------------------------------------                        
Assign in Class:       x:7500,   y:9500                                          
Assign in Structure:   x:750,    y:950

الأجوبة

using System.IO;  
using System;  
// crate a class
class aNewClass
{  
    public int x;  
    public int y;  
} 
//create a structure 
struct aNewStruc  
{  
    public int x;  
    public int y;  
}  
class strucExer4
{  
    static void Main(string[] args)   
    {  
		Console.Write("\n\nCreate a structure and assign the value and call it :\n");
		Console.Write("---------------------------------------------------------\n"); 	
        aNewClass ClassNum1 = new aNewClass();  
        ClassNum1.x = 75;  
        ClassNum1.y = 95; 
	//	ClassNum2 is ClassNum1 type	
        aNewClass ClassNum2 = ClassNum1;  
        ClassNum1.x = 7500;  
        ClassNum1.y = 9500;  
        Console.WriteLine("\nAssign in Class:       x:{0},   y:{1}", ClassNum2.x, ClassNum2.y);  
        aNewStruc StrucNum1 = new aNewStruc();  
        StrucNum1.x = 750;  
        StrucNum1.y = 950; 
	//	StrucNum2 is StrucNum1 type			
        aNewStruc StrucNum2 = StrucNum1;  
        StrucNum1.x = 75;  
        StrucNum1.y = 95; 
        Console.WriteLine("Assign in Structure:   x:{0},    y:{1}\n\n", StrucNum2.x, StrucNum2.y);  
    }  
}
هل كان المحتوى مفيد؟

تبحث عن مدرس اونلاين؟

محتاج مساعدة باختيار المدرس الافضل؟ تواصل مع فريقنا الان لمساعدتك بتأمين افضل مدرس
ماهو التخصص الذي تبحث عنه؟
اكتب هنا...