麻烦与基地和处置 [英] Trouble with base and dispose

查看:71
本文介绍了麻烦与基地和处置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要帮助的是我的代码

I need help here is my code

using System;
using System.Windows.Forms;

namespace WindowsFormsApplication5
{
    partial class LBIndustrialCtrlsBase
    {
        
        /// <summary> 
        /// Required designer variable.
        /// </summary>
        private System.ComponentModel.IContainer components = null;

        public AutoScaleMode AutoScaleMode { get; private set; }

        /// <summary> 
        /// Clean up any resources being used.
        /// </summary>
        /// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
        protected void Dispose(bool disposing)
        {
            if (disposing && (components != null))
            {
                components.Dispose();
            }
            IDisposable disposable = base as IDisposable; CS0175 here
            if (disposable != null)
            {
                disposable.Dispose(disposing); CS1501 here
            }
        }
        #region Component Designer generated code

        /// <summary> 
        /// Required method for Designer support - do not modify 
        /// the contents of this method with the code editor.
        /// </summary>
        private void InitializeComponent()
        {
            components = new System.ComponentModel.Container();
            this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
        }

        #endregion
    }
}



我一直收到以下错误


I keep getting the following error

CS0175  C# Use of keyword 'base' is not valid in this context

CS1501  C# No overload for method 'Dispose' takes 1 arguments



任何帮助将不胜感激,所以请继续



我尝试过:



我尝试过其他来源的各种解决方案来修复我处理的其他问题,这就是我解决这个问题的方法


any help will be appreciated so please go ahead

What I have tried:

I have tried various solutions from other sources to fix other problems i had with dispose and this is as far as i got in fixing this problem

推荐答案

您的类定义不包含特定的派生:

Your class definition includes no specific derivation:
partial class LBIndustrialCtrlsBase

所以它来源于仅限对象。你不能使用基类,除非你特意继承它。

这也适用于Dispose - 因为你的类没有继承,它也没有实现IDisposable。



假设示例代码实际上并不代表您的真实代码,您可以这样做:

So it is derived from object only. You can't use a base class unless you specifically inherit from it.
And that applies to Dispose as well - since your class doesn't inherit, it doesn't implement IDisposable either.

Assuming that the sample code isn't actually representative of your real code, you would do it like this:

partial class LBIndustrialCtrlsBase : MyBaseClass
    {
    /// <summary>
    /// Clean up any resources being used.
    /// </summary>
    /// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
    protected override void Dispose(bool disposing)
        {
        if (disposing && (components != null))
            {
            components.Dispose();
            }
        base.Dispose(disposing);
        }
    }


这篇关于麻烦与基地和处置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆