Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8988239
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T21:58:26+00:00 2026-06-15T21:58:26+00:00

Possible Duplicate: .NET: What are attributes? What do the square brackets mean in the

  • 0

Possible Duplicate:
.NET: What are attributes?

What do the square brackets mean in the following code:

public class LoginModel
{
    [Required]
    [Display(Name = "User name")]
    public string UserName { get; set; }

    [Required]
    [DataType(DataType.Password)]
    [Display(Name = "Password")]
    public string Password { get; set; }

    [Display(Name = "Remember me?")]
    public bool RememberMe { get; set; }
}

I have read in other questions that they are attributes, but I don’t know how they work..why do they appear in this class?
And are these only used in C#?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T21:58:28+00:00Added an answer on June 15, 2026 at 9:58 pm

    The basic idea is you are marking up your code. How they work is up to “you”

    Say you were building several forms for data entry to several classes, and you wanted to display a hint against mandatory ones and do a validation against them, and you wanted the code to do this to be common to all classes you were doing forms for and you definitely did not want to change that routine every time you added a new mandatory property to anyone of your classes.

    Using reflection, you can pass an object to a routine, get a list of all it properties, find all those with a [Required] attribute even test the instance to see it it’s not blank, and pass a list of them back without having to know anything about the class.
    Not which it is , not how many if any properties it has, what type they are. The only shared code is the RequiredAttribute class.

    Easiest way to learn it is to define one of your own and use it.

    Google .Net System.Attribute, examples abound.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Possible Duplicate: Protect .NET code from reverse engineering? we just develop a application with
Possible Duplicate: ASP.NET: how to remove 'name' attribute from server controls? On asp.net form
Possible Duplicate: Is the .Net framework required for even a single line of VB.Net?
Possible Duplicate: .NET: Determine the type of this class in its static method How
Possible Duplicate: ASP.NET “special” tags Is there a proper name for <%...> in ASP.NET,
Possible Duplicate: .NET code to send ZPL to Zebra printers My company has a
Possible Duplicate: Real world use of custom .NET attributes Just like the title said
Possible Duplicate: Storing Smtp from email friendly display name in Web.Config I'm working on
Possible Duplicate: How to create a C# class whose attributes are rows in a
Possible Duplicate: C#.NET - Why do members of a static class need to be

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.