Whole Tomato Software Forums
Whole Tomato Software Forums
Main Site | Profile | Register | Active Topics | Members | Search | FAQ
 All Forums
 Visual Assist
 Technical Support
 C# ListMethodsInCurrentFile and primary ctor

You must be registered to post a reply.
Click here to register.

Screensize:
UserName:
Password:
Format: BoldItalicizeUnderlineStrikethrough Align leftCenterAlign right Insert horizontal ruleUpload and insert imageInsert hyperlinkInsert email addressInsert codeInsert quoted textInsert listInsert Emoji
   
Message:

Forum code is on.
Html is off.

 
Check to subscribe to this topic.
   

T O P I C    R E V I E W
azur Posted - Sep 12 2025 : 09:27:37 AM

public class X {
  private readonly string _name = string.Empty;

  public X(string? name)
  {
    _name = name ?? string.Empty;
  }
  public bool IsValid()
  {
    return !string.IsNullOrEmpty(_name);
  }
}


ListMethodsInCurrentFile show me "X, X.IsValid, X.X(string? name)"

When I use C# with TargetFrameWork net9.0, I got IDE0290 'Use primary constructor'.

If I follow the suggestion then the code looks like this.


public class X(string? name) {

 private readonly string _name = name ?? string.Empty;

 public bool IsValid()
 {
   return !string.IsNullOrEmpty(_name);
 }
}

ListMethodsInCurrentFile then only show me "X(string? name)"

© 2023 Whole Tomato Software, LLC Go To Top Of Page
Snitz Forums 2000