From b05d4aa77d9dfaacfd51455c0596c3ee3b30716b Mon Sep 17 00:00:00 2001 From: Stuart Mosquera Date: Mon, 13 Oct 2025 12:19:20 -0300 Subject: [PATCH] change the type of the 'Version' property to string --- .../creating-custom-attributes.md | 4 ++-- .../snippets/conceptual/ReadAttributes.cs | 16 ++++++++-------- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/docs/csharp/advanced-topics/reflection-and-attributes/creating-custom-attributes.md b/docs/csharp/advanced-topics/reflection-and-attributes/creating-custom-attributes.md index 96d0dc8c5b99e..8f59d74aa3098 100644 --- a/docs/csharp/advanced-topics/reflection-and-attributes/creating-custom-attributes.md +++ b/docs/csharp/advanced-topics/reflection-and-attributes/creating-custom-attributes.md @@ -16,12 +16,12 @@ You can create your own custom attributes by defining an attribute class, a clas public class AuthorAttribute : System.Attribute { private string Name; - public double Version; + public string Version; public AuthorAttribute(string name) { Name = name; - Version = 1.0; + Version = "1.0"; } } ``` diff --git a/docs/csharp/advanced-topics/reflection-and-attributes/snippets/conceptual/ReadAttributes.cs b/docs/csharp/advanced-topics/reflection-and-attributes/snippets/conceptual/ReadAttributes.cs index 4478625420dce..2a419327ef07c 100644 --- a/docs/csharp/advanced-topics/reflection-and-attributes/snippets/conceptual/ReadAttributes.cs +++ b/docs/csharp/advanced-topics/reflection-and-attributes/snippets/conceptual/ReadAttributes.cs @@ -10,14 +10,14 @@ public class AuthorAttribute : System.Attribute { string Name; - public double Version; + public string Version; public AuthorAttribute(string name) { Name = name; // Default value. - Version = 1.0; + Version = "1.0"; } public string GetName() => Name; @@ -39,7 +39,7 @@ public class SecondClass // Class with multiple Author attributes. // -[Author("P. Ackerman"), Author("R. Koch", Version = 2.0)] +[Author("P. Ackerman"), Author("R. Koch", Version = "2.0")] public class ThirdClass { // ... @@ -67,23 +67,23 @@ private static void PrintAuthorInfo(System.Type t) { if (attr is AuthorAttribute a) { - System.Console.WriteLine($" {a.GetName()}, version {a.Version:f}"); + System.Console.WriteLine($" {a.GetName()}, version {a.Version}"); } } } } /* Output: Author information for FirstClass - P. Ackerman, version 1.00 + P. Ackerman, version 1.0 Author information for SecondClass Author information for ThirdClass - R. Koch, version 2.00 - P. Ackerman, version 1.00 + R. Koch, version 2.0 + P. Ackerman, version 1.0 */ // // -[Author("P. Ackerman", Version = 1.1)] +[Author("P. Ackerman", Version = "1.1")] class SampleClass { // P. Ackerman's code goes here...