Ddo1.com WebMaster & Kodlama Forumu

Tam Versiyon: C# Struct Yapısı (Kullanımı ve Oluşturma)
Şu anda arşiv modunu görüntülemektesiniz. Tam versiyonu görüntülemek için buraya tıklayınız.
Default Struct

Alıntı:
PHP Kod:
       struct MyStruct
       
{

       



Örnek Struct
PHP Kod:
struct Ornek
       
{
           public int int_ getset; }
           public bool bool_ getset; }
           public string string_ getset; }
           public float float_ getset; }
       }


Değişken tanımlama;
Ornek ornek_tanimlama;
Ornek ornek_nesne = new Ornek();
ornek_nesne.bool_ true




Struct yapısını formlar arasında kullanmak isterseniz aşağıda ki kod size yardımcı olacaktır.
PHP Kod:
       public struct Ornek
       
{
           public int int_ getset; }
           public bool bool_ getset; }
           public string string_ getset; }
           public float float_ getset; }
           public int MyProperty getset; }

       }

Kodda gördüğünüz gibi Public kullanarak bunu sağladıkÖrnek kullanım
PHP Kod:
  Form1.Ornek ornek = new Form1.Ornek(); 
PHP Kod:
           ornek.string_ "String ataması yapıldı"




Open Source Example (Örnek Proje)

PHP Kod:
using System;
using System.Windows.Forms;

namespace 
WindowsFormsApplication4
{
   public partial class Form1 Form
   
{
       struct Bilgiler
       
{
           public int kisi_sayisi getset; }
           public string topluluk_ismi getset; }
           public bool hepsi_erkekmi getset; }
       }
       public Form1()
       {
           InitializeComponent();

       }

       Bilgiler bilgi;
       private void btnAtama_Click(object senderEventArgs e)
       {
           bilgi.hepsi_erkekmi true;
           bilgi.kisi_sayisi 30;
           bilgi.topluluk_ismi "Erkek Topluluğu";
           MessageBox.Show("Atama Yapıldı");
       }

       private void btnGoster_Click(object senderEventArgs e)
       {
           
           MessageBox
.Show("Topluluk İsmi : " bilgi.topluluk_ismi +"\n" "Hepsi Erkekmi : " bilgi.hepsi_erkekmi "\n" "Kişi Sayısı : " bilgi.kisi_sayisi);
       }
   }