简体   繁体   中英

Can a certain overloaded constructor, show certain overloaded methods?

I have a class with both a overloaded constructor and a overloaded method.

If I initiate the class with parameters, the idea would be that I then didn't need to fill this information into my method. But as things grow it can get a bit confusing.

I wanted to know if there is a way of either telling C# or Visual Studio not to show the method in the IntelliSense if a certain constructor is called, hopefully in a clean and neat way without any "hacks".

Thanks in advance.

No, you can't change the behavior of IntelliSense that way.

The issue you're facing is actually a code smell regarding your class design.

If you have certain methods that aren't of any use unless a given constructor was used, you should probably split the class so that the different functionality is clearly delineated.

It might make sense to have a base class of the common behavior and subclasses for each of the different types of constructors. This would effectively do what you're asking for, and follow proper object-oriented design.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM