Click here to Skip to main content
15,867,308 members
Articles / Programming Languages / C#

A ToString Replacement that Recognizes Different Data Types

Rate me:
Please Sign up or sign in to vote.
2.00/5 (4 votes)
28 Oct 2021CPOL1 min read 5.4K   4  
Most data types have a built-in ToString method, but not all, and what's more, the default method can throw an error if, for example, the object is null.
Not all data types have a built-in ToString method. Moreover, built-in methods can throw an error if, for example, an object is empty, or can only return the type name. This tip shows how to build a universal method (for example in extensions) that recognizes the type of data and converts it into a meaningful text string.

Views

Daily Counts

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Retired
Poland Poland
Retired administrator of Microsoft systems, such as corporate AD and corporate Echange e-mail, creator of their on-prem implementation, assembling programs for his own use since 1982 (then in machine code 8080, today most often C #)

Comments and Discussions