Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Error with C# Partial classes

I am using partial classes to split some functionality between 2 files, but I am getting an error. What am I doing wrong?

A1.cs:

private partial class A
{
    private string SomeProperty { get { return "SomeGeneratedString"; } }       
}

A2.cs:

private partial class A
{
    void SomeFunction()
    {
        //trying to access this.SomeProperty produces the following compiler error, at least with C# 2.0
        //error CS0117: 'A' does not contain a definition for 'SomeProperty'
    }
}
like image 612
Adam Tegen Avatar asked Oct 08 '08 21:10

Adam Tegen


People also ask

How does C handle errors?

As such, C programming does not provide direct support for error handling but being a system programming language, it provides you access at lower level in the form of return values. Most of the C or even Unix function calls return -1 or NULL in case of any error and set an error code errno.

What are the 3 errors in coding?

When developing programs there are three types of error that can occur: syntax errors. logic errors. runtime errors.

What is error and warning in C?

Errors report problems that make it impossible to compile your program. GCC reports errors with the source file name and line number where the problem is apparent. Warnings report other unusual conditions in your code that may indicate a problem, although compilation can (and does) proceed.


2 Answers

Are the two partial classes in the same namespace? That could be an explanation.

like image 200
Sklivvz Avatar answered Sep 29 '22 16:09

Sklivvz


Same answer as @Andrey K but in simple terms

Set the build action of all your partial classes to 'Compile' using the 'Properties' windows of each of those files

Properties window -> Build action property

like image 22
Ram Avatar answered Sep 29 '22 16:09

Ram