[C#] giúp đỡ mình về lỗi less accessible than method

nguyen204

Mr & Ms Pac-Man
Lão Làng GVN
Tham gia ngày
20/5/05
Bài viết
255
Reaction score
93
đây là source code của bài tập
Mã:
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;

namespace GTS1_Console
{
    class Program
    {
        const int MAX = 100;
        struct Graph
        {
            
            public int[,] A;
            public int n;
            
        }
        public static int[] Tour;
        public static int[] Check;

        public static void LoadFile(Graph g)
        {
            System.String s = null;
            string[] token;
            StreamReader myfile = null;

            try
            {
                myfile = File.OpenText(@"d:\New.txt");
                s = myfile.ReadLine();
                token = s.Split();
                g.n = token.Length;
                g.A = new int[g.n, g.n];
                int[] Tour = new int[MAX];
                int[] Check = new int[MAX];
                for (int i = 0; i < g.n; i++)
                {
                    s = myfile.ReadLine();
                    token = s.Split();
                    for (int j = 0; j < g.n; j++)
                        g.A[i, j] = int.Parse(token[j]);
                }
            }
            catch (Exception exc)
            {
                Console.Write("Khong mo file duoc!");
            }
            finally
            {
                if (myfile != null)
                {
                    myfile.Close();
                }
            }
        }

        public static int TimDinhChiPhiThapNhat(Graph g, int v)
        {
            int costmin = 65536; //= MAX - INT;
            int vtmin = -1;
            for (int i = 0; i < g.n; i++)
            {
                if (i != v && Check[i] == 0)
                    if (g.A[v, i] < costmin)
                    {
                        costmin = g.A[v, i];
                        vtmin = i;
                    }
            }
            return vtmin;
        }

        public static int GTS_1(Graph g, int u)
        {
            Check[u] = 1;
            int k = 0;
            int v = u;
            int w = 0;
            Tour[k++] = u;
            int cost = 0;
            do
            {
                w = TimDinhChiPhiThapNhat(g, v);
                Tour[k++] = w;
                cost += g.A[v, w];
                v = w;
                Check[w] = 1;
            } while (k < g.n);
            Tour[k] = u;
            cost += g.A[v, u];
            return cost;
        }

        static void Main(string[] args)
        {
            Graph g;
            LoadFile(g);
            int u;
            Console.Write("Moi nhap u: ");
            u = int.Parse(Console.ReadLine());
            Console.Write("Chi phi thap nhat la: " + GTS_1(g, u));
        }
    }
}

Lỗi:
Mã:
Error	3	Inconsistent accessibility: parameter type 'GTS1_Console.Program.Graph' is less accessible than method 'GTS1_Console.Program.GTS_1(GTS1_Console.Program.Graph, int)'	D:\Training C\C#\GTS1_Console\GTS1_Console\Program.cs	74	27	GTS1_Console

Error	1	Inconsistent accessibility: parameter type 'GTS1_Console.Program.Graph' is less accessible than method 'GTS1_Console.Program.LoadFile(GTS1_Console.Program.Graph)'	D:\Training C\C#\GTS1_Console\GTS1_Console\Program.cs	22	28	GTS1_Console

Error	2	Inconsistent accessibility: parameter type 'GTS1_Console.Program.Graph' is less accessible than method 'GTS1_Console.Program.TimDinhChiPhiThapNhat(GTS1_Console.Program.Graph, int)'	D:\Training C\C#\GTS1_Console\GTS1_Console\Program.cs	58	27	GTS1_Console

Mình mới tập tành tự học C# nên còn gà :( , các bạn giúp đỡ mình với!
 
Chỉnh sửa cuối:
struct Graph - > public struct Graph
Hoặc để struct Graph ngoài Program
Mặc định của struct là private
 
Chỉnh sửa cuối:
Cám ơn nha :D , Mình fix đc rồi \m/
Cám ơn bạn nhiều \m/
 
Back
Top