C#自定义UserControl帮助 [英] C# Custom UserControl help

查看:91
本文介绍了C#自定义UserControl帮助的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,编码人员,我需要您的帮助才能继续进行我的项目.
我是一名业余新手,这个应用程序是出于我的个人喜好.

所以我有这段代码:

Hello coders, I require your help to continue with my project.
I''m an amateur newbie btw, this application is for my personal joy.

So I have this code:

namespace GC
{
    public partial class MyControl : UserControl
    {
        //-- Design stuff
        //-- Properties
        //-- Events
    }
}



我想创建一个MyControl类之外的List<MyControl>,它可由GC名称空间内的所有类/结构/所有对象访问,但不能由该名称空间之外的任何对象访问.



I want to make a List<MyControl> that is outside the MyControl class, accessible by all classes/structs/whatever within the GC namespace, but not accessible by anything outside that namespace.

How can this be done?

推荐答案

您正在寻找正确的可访问性级别(C#参考) [ ^ ]我怀疑只有将名称空间限制为一个程序集时,您才能实现此目的.然后,内部访问修饰符将为您工作.

问候,

曼弗雷德(Manfred)
You are looking for the correct Access Modifiers[^]. Looking at the explanations planted on Accessibility Levels (C# Reference)[^] I suspect you can only achieve this if your namespace is restricted to one assembly. Then the access modifier internal would work for you.

Regards,

Manfred


请参阅我对问题的评论.

命名空间不是控制访问的单元或任何其他类型的程序包.这样的单元或程序包就是程序集,但是程序集或名称空间之间没有任何关联,也就是说,一个程序集可以在多个名称空间中定义类型,并且可以在不同的程序集中使用相同的确切名称空间来定义类型.在不同的命名空间中使用定义也代表着相同的观点:没有任何障碍.更确切地说,名称空间仅定义事物的命名方式,而不是访问的定义.

在访问时,程序集边界使访问修饰符与internalprotected internal不同,关键字内部"的意思是公共但具有相同的程序集".

最后,即使使用了访问修饰符控制的访问,无论是否跨程序集,使用反射都可以完全透明.使用反射,所有privateprotectedinternalinternal protected声明以及public都可以同等访问.
-SA
Please see my comment to the question.

A namespace is not a unit or any other kind of package controlling access. Such unit or package is the assembly, but there are no any correlation between assemblies or namespaces, that is, one assembly can define types in several namespaces, and the same exact namespace can be used in different assemblies for defining of types. The same stands for using definitions in different namespaces: there are no any barriers. More exactly, the namespaces only define how things are named, not access.

When it comes to access, the assembly boundary make access modifiers public different from internal or protected internal, the key word "internal" means "public but withing the same assembly".

Finally, even the access controlled by access modifiers, across assemblies or not, is fully transparent with the use of Reflection. With Reflection, all private, protected, internal and internal protected declarations are equally accessible, as well as public.

—SA


如果在库中,则创建一个DLL并将该DLL包括在外部项目的引用中.

现在,通过使用,您可以将此命名空间包含到外部项目中,然后就可以开始使用它了.

If this is in a library then, create a DLL and include this DLL in References of your outside projects.

Now by using you can include this namespace to your outside project and you can start use it.

using GC;



即使您在项目中引用,也必须使用语句将其包括在内.

请参考了解C#2.0中的命名空间 [



Even if you are referring in project you have to include by using statement.

Refer Understanding Namespaces in C# 2.0[^] for more reference.

thanks
Rushi


这篇关于C#自定义UserControl帮助的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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