简体   繁体   English

如何将列表从表单发送到另一个表单

[英]How to send a list from a form to another one

I have two forms in a Windows Forms project: Form1 and aCurso . Windows窗体项目中有两个窗体: Form1aCurso

I'm trying to send a List with objects of a class called curso (I mean: List<curso> ) from Form1 to aCurso . 我正在尝试从Form1aCurso发送包含名为curso (我的意思是: List<curso> )的类的对象的List<curso>

But Visual Studio show this: 但是Visual Studio显示了这一点:

Accessibility inconsistency: The type of parameter List<curso> is less accessible than the method aCurso.aCurso(List<curso>) . 可访问性不一致:与方法aCurso.aCurso(List<curso>)相比,参数List<curso>类型更难访问。

So, here is the code from Form1 : 因此,这是Form1的代码:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace _18_05_18
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }
        List<curso> cursos = new List<curso>();
        private void btnAC_Click(object sender, EventArgs e)
        {
            Form f = new aCurso(cursos);
            f.Show();
        }
    }
}


Here's code from aCurso : 这是来自aCurso的代码:

 using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; namespace _18_05_18 { public partial class aCurso : Form { List<curso> cursos = new List<curso>(); public aCurso(List<curso> cursos) { InitializeComponent(); this.cursos = cursos; } } } 


Here's code from class curso : 这是来自curso类的代码:

 using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace _18_05_18 { class curso { private string nombre; public curso(string nombre) { this.nombre = nombre; } } } 

You cannot expose a public method signature where some of the parameter types of the signature are not public. 如果签名的某些参数类型不是公共的,则不能公开公共方法签名。 It wouldn't be possible to call the method from outside since the caller couldn't construct the parameters required. 由于调用者无法构造所需的参数,因此无法从外部调用该方法。

All you have to do is make curso class public 所有你需要做的就是让curso班公

public class curso
{
    private string nombre;
    public curso(string nombre)
    {
        this.nombre = nombre;
    }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 将事件从一种形式发送到另一种形式 - Send event from one form to another form 将值从一个表单发送到另一个表单 - Send values from one form to another form 如何将信息从一种形式发送到另一种形式 - How do i send the information from one form to another 如何使用 MemoryStream 将数据从一种形式发送到另一种形式 - How can send data from one form to another using MemoryStream 如何从以一种形式创建的文本框中读取值并将其发送到另一种形式? - How to read values from textboxes I created in one form and send them to another form? 将键盘事件从一种形式发送到另一种形式 - Send Keyboard Events from one Form to another Form 如何将数据从datagrid行(form2)发送到已打开form2的usercontrol(form1)中的另一个行 - How to send data from a datagrid row (form2) on click to another one in a usercontrol(form1) that have opened the form2 如何在WinForms C#中从一种形式向另一种形式发送实时消息? - How to send live messages from one form to another in winforms c#? 如何使用查询字符串和输入表单将数据从一页发送到另一页? - How to send data from one page to another page with querystring and input form? 家庭作业如何将值从一种形式传递到另一种形式的列表中的对象 - Homework how to pass values from one form to an object in a list in another form
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM