[C #] Accessibility inconsistencies

Source: Internet
Author: User

"Problem"


"Analysis"

Each type referenced in the formal parameter list of a return type and method must have at least the same accessibility as the method itself.

One is that the access level of the return parameter is less than the access level of the function.

That is, when you define a method that returns a parameter, this error occurs if the access level of the returned parameter is lower than the access level of the method.

This is understandable, and if the returned parameter cannot be accessed, the returned method of the definition is also incorrect.


"instance"

SmartPark.BLL.ParkTicketTypeManager:

Public Park_ticekttype Getbyparkid (long Parkid)        {            return null;        }

SmartPark.Models.Park_TicketType:

namespace smartpark.models{[Serializable ()] <span style= "color: #ff0000;"        >class park_ticekttype</span> {private int tickettype_park_id;            public int tickettype_park_id {get {return tickettype_park_id;}        set {tickettype_park_id = value;}        } private int Tickettypeid;            public int Tickettypeid {get {return tickettypeid;}        set {Tickettypeid = value;}        } private string Tickettypename;            public string Tickettypename {get {return tickettypename;}        set {tickettypename = value;}        } private int parkid;            public int Parkid {get {return parkid;}        set {Parkid = value;}        } private string Parkname;            public string Parkname {get {return parkname;}        set {parkname = value;}        } private bool Deleteflag; public bool DeleTeflag {get {return deleteflag;}        set {Deleteflag = value;}        } private string Demo;            public string Demo {get {return Demo;}        set {demo = value;} }    }}

The access level of the function is public, the access level of the returned parameter is private, and when you define a method that returns a parameter, this error occurs if the access level of the returned parameter is lower than the access level of the method



When you create a new class, there is no public in front of class, plus it's right.

Change to:

namespace smartpark.models{[Serializable ()] public class Park_ticekttype {private int tickettype_park_id        ;            public int tickettype_park_id {get {return tickettype_park_id;}        set {tickettype_park_id = value;}        } private int Tickettypeid;            public int Tickettypeid {get {return tickettypeid;}        set {Tickettypeid = value;}        } private string Tickettypename;            public string Tickettypename {get {return tickettypename;}        set {tickettypename = value;}        } private int parkid;            public int Parkid {get {return parkid;}        set {Parkid = value;}        } private string Parkname;            public string Parkname {get {return parkname;}        set {parkname = value;}        } private bool Deleteflag; public bool Deleteflag {get {return deleteflag;        } set {Deleteflag = value;}        } private string Demo;            public string Demo {get {return Demo;}        set {demo = value;} }    }}







[C #] Accessibility inconsistencies

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.