[ artriba @ 16.01.2008. 10:52 ] @
Imam dva fajla
Program.cs...
Code:
using System;
namespace Test
{
    class Program
    {
        static void Main(string[] args)
        {
            Class1 obj = new Class1();
            obj.Write();
        }
    }
}

i Class1.cs...
Code:
using System;
namespace Test
{
    class Class1
    {
        public void Write()
        {
            Console.WriteLine("Some shit I wrote");
        }
    }
}

kad ih želim kompajlirat preko command linea dobijem ove greške
Code:
Setting environment for using Microsoft Visual Studio 2008 x86 tools.

C:\Windows\system32>cd c:\

c:\>csc /t:library Class1.cs
Microsoft (R) Visual C# 2008 Compiler version 3.5.21022.8
for Microsoft (R) .NET Framework version 3.5
Copyright (C) Microsoft Corporation. All rights reserved.


c:\>csc /r:Class1.dll Program.cs
Microsoft (R) Visual C# 2008 Compiler version 3.5.21022.8
for Microsoft (R) .NET Framework version 3.5
Copyright (C) Microsoft Corporation. All rights reserved.

Program.cs(8,13): error CS0122: 'Test.Class1' is inaccessible due to its
        protection level
Program.cs(8,30): error CS0122: 'Test.Class1' is inaccessible due to its
        protection level
Program.cs(8,26): error CS0143: The type 'Test.Class1' has no constructors
        defined
Program.cs(9,17): error CS1061: 'Test.Class1' does not contain a definition for
        'Write' and no extension method 'Write' accepting a first argument of
        type 'Test.Class1' could be found (are you missing a using directive or
        an assembly reference?)

c:\>
[ mmix @ 16.01.2008. 11:49 ] @
Kao sto ti greske i kazu:

1. Da bi Program.Main video klasu Test.class1 moras da je deklarises kao public ili internal
2. Da bi mogao da instanciras Class1 ta klasa mora da ima public konstruktor:

Code:

using System;
namespace Test
{
    public class Class1
    {
        public Class1() {}
        public void Write()
        {
            Console.WriteLine("Some shit I wrote");
        }
    }
}