Write a program in C# Sharp to declares a structure with a property, a method, and a private field

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

Write a program in C# Sharp to declares a structure with a property, a method, and a private field.

Expected Output:

Declares a structure with a property, a method, and a private field :               
----------------------------------------------------------------------           
The stored value is: 15

الأجوبة

using System;
struct newStruct
{
    private int num;

    public int n
    {
        get 
        {
            return num;
        }
        set 
        {
            if (value < 50)
                num = value;
        }
    }
    public void clsMethod()
    {
        Console.WriteLine("\nThe stored value is: {0}\n", num);
    }
}
class strucExer6
{
    public static void Main()
    {
		Console.Write("\n\nDeclares a structure with a property, a method, and a private field :\n");
		Console.Write("----------------------------------------------------------------------\n");	
        newStruct myInstance = new newStruct();
        myInstance.n = 15;
        myInstance.clsMethod();
    }
}
هل كان المحتوى مفيد؟

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

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