[英]How to send a list from a form to another one
I have two forms in a Windows Forms project: Form1
and aCurso
. Windows窗体项目中有两个窗体: Form1
和aCurso
。
I'm trying to send a List with objects of a class called curso
(I mean: List<curso>
) from Form1
to aCurso
. 我正在尝试从Form1
向aCurso
发送包含名为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 methodaCurso.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();
}
}
}
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; } } }
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.