What's new

C# Pa help po ulet HAHAHAH about sa Delegate

Status
Not open for further replies.

Chunchunmaru

Eternal Poster
Joined
Aug 31, 2021
Posts
766
Reaction
288
Points
459
Nababaliw na ko, pano ba tawagin yung delegate class sa main method?
Eto yung codes:
C#:
//Code nung delegate class
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Account_Registration
{
    public delegate long DelegateNumber(long number);
    public delegate string DelegateText(string txt);

    class StudentInfoClass
    {
        static string FirstName = " ", LastName = " ", MiddleName = " ", Address = " ", Program = " ";
        static long Age = 0, ContactNo = 0, StudentNo = 0;

        public static string GetFirstName(string FirstName)
        {
            return FirstName;
        }

        public static string GetLastName(string LastName)
        {
            return LastName;
        }

        public static string GetMiddleName(string MiddleName)
        {
            return MiddleName;
        }

        public static string GetAddress(string Address)
        {
            return Address;
        }

        public static string GetProgram(string Program)
        {
            return Program;
        }

        public static long GetAge(long Age)
        {
            return Age;
        }

        public static long GetContactNo(long ContactNo)
        {
            return ContactNo;
        }

        public static long GetStudentNo(long StudentNo)
        {
            return StudentNo;
        }
    }
}

Code nung windows form
C#:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace Account_Registration
{
    public partial class FrmRegistration : Form
    {
        DelegateText delegateAddition;
        DelegateNumber delegateAddition;

        public FrmRegistration()
        {
            InitializeComponent();
            delegateAddition = new DelegateText(StudentInfoClass.GetProgram);
            delegateAddition = new DelegateNumber(StudentInfoClass.GetAge);
        }

        private void NextButton_Click(object sender, EventArgs e)
        {

        }
    }
}

Mali ba yung pag ka code ko sa delegate? Ito yung sinusunod ko
IMG_20211001_192012.JPG


Eto yung nang yayari
IMG_20211001_191651.jpg

Di ko sure kung saan ako mali, pero feel ko dun sa delegate, naninibago kase ako kase bagong topic to
 

Attachments

txtStuNo name ng textbox sa design
C#:
 StudentInfoClass.StudentNo = long.Parse(txtStuNo.Text);

Eto sa form 2
C#:
LStudentNo.Text = DelStudentNo(StudentInfoClass.StudentNo).ToString();
 
Status
Not open for further replies.
Back
Top