PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Tuesday, December 13, 2022

[FIXED] How to Call a non standard Constructor

 December 13, 2022     c#, constructor, syntax     No comments   

Issue

I'm new to C# and having problems with the usage of a non standard constructor. This is a part of the interface of the library I'm using (QRCoder) after the latest update:

public class Contact
  {
    [Obsolete("This constructor is deprecated. Use WithCombinedAddress instead.")]
    public Contact(string name, string country, string addressLine1, string addressLine2);
    [Obsolete("This constructor is deprecated. Use WithStructuredAddress instead.")]
    public Contact(string name, string zipCode, string city, string country, string street = null, string houseNumber = null);

    public static Contact WithCombinedAddress(string name, string country, string addressLine1, string addressLine2);
    public static Contact WithStructuredAddress(string name, string zipCode, string city, string country, string street = null, string houseNumber = null);
    public override string ToString();

Before the update, this code used to work:

  Contact contactCreditor;
  string name, zipCode, city, country, street, housenr, strIban;
  ... 
  contactCreditor = new SwissQrCode.Contact (name, zipCode, city, country, street, housenr);

Now I get the error message

This constructor is deprecated. Use WithStructuredAddress instead.

How can I modify my code to use this new constructor?


Solution

The class no longer has a non deprecated constructor, instead call the static initializer.

Contact contactCreditor;
  string name, zipCode, city, country, street, housenr, strIban;
  ... 
  contactCreditor = SwissQrCode.Contact.WithStructuredAddress(
                        name,
                        zipCode,
                        city,
                        country,
                        street,
                        housenr);


Answered By - Jodrell
Answer Checked By - Marilyn (PHPFixing Volunteer)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing