Creating a generic method in C#

后端 未结 6 1258
耶瑟儿~
耶瑟儿~ 2020-12-04 09:45

I am trying to combine a bunch of similar methods into a generic method. I have several methods that return the value of a querystring, or null if that querystring does not

6条回答
  •  日久生厌
    2020-12-04 10:06

    I like to start with a class like this class settings { public int X {get;set;} public string Y { get; set; } // repeat as necessary

     public settings()
     {
        this.X = defaultForX;
        this.Y = defaultForY;
        // repeat ...
     }
     public void Parse(Uri uri)
     {
        // parse values from query string.
        // if you need to distinguish from default vs. specified, add an appropriate property
    
     }
    

    This has worked well on 100's of projects. You can use one of the many other parsing solutions to parse values.

提交回复
热议问题