0

Is there any possibility to split classes for a two files like in C++? I mean like defining in header file and declaring in cpp in C++. I've read a bit about partial classes but is it that what i need? If it's not possible can you give me some advices how to manage it cause it looks ugly and messy for me.

0

2 Answers 2

4

Why do you need this? just because it looks messy?

If you use Visual Studio you can hide methods bodies with Ctrl+M+O. I use it to get the overview of the code.

Partial classes are design for splinting the generated code from your code. You shouldn't use it to clean up. If your code does look messy try to refactor it e.g. write helper methods, put some logic in a separate class.

C++ has header files only to maintain backward compatibility with C. There are a lot of problems with it e.g. you write a template class and you change the signature in definition, but forgot to change it in declaration and as a result, you get some weird error.

Sign up to request clarification or add additional context in comments.

Comments

4

In response to your edit: You can collapse sections of the code if you are concerned about a large class file.

You can use the partial keyword.

SomeFile.cs

public partial class MyClass
{
}

SomeOtherFile.cs

public partial class MyClass
{
}

Please see MSDN for additional info and restrictions as there are some rules that apply.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.