小编Sam*_*hid的帖子

如何在C#中传递当前实例的引用

例如像(ref this)这样的东西不起作用......例如,这失败了:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace CopyOfThis
{
    class Program
    {
        static void Main(string[] args)
        {
            View objView = new View();
            objView.Boo();
            objView.ShowMsg("The objView.StrVal is " + objView.StrVal);
            Console.Read();
        }
    } //eof Program


    class View
    {
        private string strVal;
        public string StrVal
        {
            get { return strVal; }
            set { strVal = value; } 

        }
        public void Boo()
        {
            Controller objController = new Controller(ref this);
        }

        public void ShowMsg ( string msg ) 
        {
            Console.WriteLine(msg); …
Run Code Online (Sandbox Code Playgroud)

c# reference

6
推荐指数
2
解决办法
1万
查看次数

标签 统计

c# ×1

reference ×1