使用C#列表 [英] Working with C# lists

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

问题描述

我试图了解列表如何在C#中工作,但由于收到这些消息而无法运行我的应用程序:

I'm trying to understand how does lists work in C# but I can't run my application because I get those messages:

错误1可访问性不一致: 属性类型"ClaseLista.ListNode"为 比财产少 'ClaseLista.List.PrimerNodo'C:\ Documents 和 设置\ Usuario \ Escritorio \ Listas \ ClaseLista \ List.cs 19 25 ClaseLista

Error 1 Inconsistent accessibility: property type 'ClaseLista.ListNode' is less accessible than property 'ClaseLista.List.PrimerNodo' C:\Documents and Settings\Usuario\Escritorio\Listas\ClaseLista\List.cs 19 25 ClaseLista

错误2辅助功能不一致: 属性类型"ClaseLista.ListNode"为 比财产少 'ClaseLista.List.UltimoNodo'C:\ Documents 和 设置\ Usuario \ Escritorio \ Listas \ ClaseLista \ List.cs 24 25 ClaseLista

Error 2 Inconsistent accessibility: property type 'ClaseLista.ListNode' is less accessible than property 'ClaseLista.List.UltimoNodo' C:\Documents and Settings\Usuario\Escritorio\Listas\ClaseLista\List.cs 24 25 ClaseLista

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

using ClaseLista;

namespace Listas
{
    class Program
    {
        static void Main(string[] args)
        {
            List Lista1 = new List();
            int opcion = 1;
            while (opcion > 0 && opcion < 3)
            {
                Console.WriteLine("xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx");
                Console.WriteLine("x Menú Principal (dos datos) x");
                Console.WriteLine("xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx");
                Console.WriteLine("x                            x");
                Console.WriteLine("x 1: Insertar Alumnos        x");
                Console.WriteLine("x 2: Imprimir Lista          x");
                Console.WriteLine("x 3: Salir                   x");
                Console.WriteLine("x                            x");
                Console.WriteLine("xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx");
                Console.Write("Ingrese opción: ");
                opcion = int.Parse(Console.ReadLine());
                switch (opcion)
                {
                    case 1: int numero; string nombre, codigo;
                        Console.Write("Ingrese número de elementos: ");
                        numero = int.Parse(Console.ReadLine());
                        for (int i = 1; i <= numero; i++)
                        {
                            Console.WriteLine("Datos del alumno " + i);
                            Console.Write("Ingrese Nombre: ");
                            nombre = (Console.ReadLine());
                            Console.Write("Ingrese Codigo: ");
                            codigo = (Console.ReadLine());
                            Lista1.InsertaInicio(nombre, codigo);
                        }
                        break;
                    case 2:
                        if (Lista1.EsVacio())
                        {
                            Console.WriteLine("Lista Vacia");
                        }
                        else
                        {
                            Lista1.Imprimir();
                        }
                        break;
                }
            }
        }
    }
}


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

namespace ClaseLista
{
    public class List
    {
        //Constructor
        private ListNode primerNodo;
        private ListNode ultimoNodo;
        public List()
        {
            primerNodo = null;
            ultimoNodo = null;
        }
        //Propiedades
        public ListNode PrimerNodo
        {
            get { return primerNodo; }
            set { primerNodo = value; }
        }
        public ListNode UltimoNodo
        {
            get { return ultimoNodo; }
            set { ultimoNodo = value; }
        }
        //insertar al inicio
        public void InsertaInicio(object nom, object cod)
        {
            if (EsVacio())
                primerNodo = ultimoNodo = new ListNode(nom, cod, null);
            else
            {
                primerNodo = new ListNode(nom, cod, primerNodo);
            }
        }
        //comprobar si es vacio
        public bool EsVacio()
        {
            return primerNodo == null;
        }
        //Imprimir
        public void Imprimir()
        {
            ListNode current = primerNodo;
            while (current != null)
            {
                Console.WriteLine("|" + current.Nombre + " " + current.Codigo);
                current = current.Siguiente;
            }
        }
    }
}


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

namespace ClaseLista
{
    class ListNode
    {
        //Constructor
        private object nombre;
        private object codigo;
        private ListNode siguiente;
        public ListNode()
        {
            nombre = null;
            codigo = null;
            siguiente = null;
        }
        public ListNode(object nomb, object cod, ListNode sig)
        {
            nombre = nomb;
            codigo = cod;
            siguiente = sig;
        }
        //Propiedades
        public object Nombre
        {
            get { return nombre; }
            set { nombre = value; }
        }
        public object Codigo
        {
            get { return codigo; }
            set { codigo = value; }
        }
        public ListNode Siguiente
        {
            get { return siguiente; }
            set { siguiente = value; }
        }
    }
}

我该怎么办?

推荐答案

您还需要使ListNode公开...

You need to make ListNode public as well...

public class ListNode

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

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