Syntax and initial value of the attributes (property) of C # 6.0 _c# Tutorial

Source: Internet
Author: User

Last night I learned something new about C # 6.0.

There is a table created in the database:

CREATE TABLE [dbo]. [Toollocation]
(
 [TOOLLOCATION_NBR] SMALLINT IDENTITY (1,1) NOT null PRIMARY KEY,
 [LocationName] NVARCHAR (a) not NULL,
 [ Description] NVARCHAR null,
 [isactive] BIT not NULL DEFAULT (1)
) go
Source Code

Look at the contrast and the wording:

Using System;
Using System.Collections.Generic;
Using System.Linq;
Using System.Text;
Using System.Threading.Tasks;

Namespace Insus.NET.Models
{public
 class toollocation
 {public short
  TOOLLOCATION_NBR {get; set;} = 1;

  public string LocationName {get; set;} = String. Empty;

  public string Description {get; set;} = String. Empty;

  public bool IsActive {get; set;} = true;
 }}
Source Code

The following insus.net demonstrates creating an entity:

Using Insus.NET.Models;
Using System;
Using System.Collections.Generic;
Using System.Linq;
Using System.Text;
Using System.Threading.Tasks;

Namespace Insus.NET.Entities
{public
 class toollocationentity
 {public
  ienumerable< Toollocation> toollocations ()
  {return
   new list<toollocation> () {
    new toollocation (),
    New Toollocation {TOOLLOCATION_NBR = 2, LocationName = "A2", Description = "A2 CNC", IsActive = true},
    new Toollocati on {TOOLLOCATION_NBR = 3, LocationName = "C4", Description = "C4 CNC", IsActive = False}}}
Source Code

It will have three objects, and the first object is to use the default value.
In the controller:

In the ASP.net MVC view, display this data:

Look at the effect of the operation:

Above this C # 6.0 properties of the syntax and the initial value of the explanation is small series to share all the content, hope to give you a reference, but also hope that we support cloud habitat community.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.