Member asked more than once error message?

I use C # in vs2010 and learn oop; my first attempt to declare the transfer of an object in my AppCode folder continues to give me an error message that

this member defined more than once ambiguity between Submission.SubmissionId and Submission.SubmissionId 

This error generates every variable (CustId, BroId, Coverage). I followed the model I found in the tutorial for syntax; This is problem? Code below:

 using System; using System.Collections.Generic; using System.Linq; using System.Web; public class Submission { int SubmissionId; int CustId; int BroId; int Coverage; //Array Product[] products; public Submission() {} public int SubmissionId { get { return SubmissionId; } set { SubmissionId = value; } } public int CustId { get { return CustId; } set { CustId = value; } } public int BroId { get { return BroId; } set { BroId = value; } } public int Coverage { get { return Coverage; } set { Coverage = value; } } } 
+4
source share
7 answers

The problem is that you specify the same variable name and property.

You can fix this by giving them different names:

 public class Submission { public Submission() {} private int submissionId; public int SubmissionId { get{ return this.submissionId; } set{ this.submissionId = value; } } private int custId ; public int CustId { get{ return this.custId ; } set{ this.custId = value; } } private int broId ; public int BroId { get{ return this.broId ; } set{ this.broId = value; } } private int coverage; public int Coverage { get{ return this.coverage; } set{ this.coverage= value; } } } 

Read What is the best way to name fields and properties .


Alternatively, you can use Authorized Properties :

In C # 3.0 and later, properties declare a property more concise when there is no additional logic required in property accessories. They also allow you to create client code for creating objects.

Here we go:

 public class Submission { public Submission() {} public int SubmissionId { get; set; } public int CustId { get; set; } public int BroId { get; set; } public int Coverage { get; set; } } 
+5
source

Declare your properties as follows:

 private int _submissionId; public int SubmissionId { get { return _submissionId; } set { _submissionId = value; } } 

or you can use Authorized Properties (C # 3.0 or later, which do the same, but require less input)

 public int SubmissionId { get; set; } 
+3
source

You give your public and private members the same name. You cannot do this.
You can specify a prefix to all your private members, such as underscores (_), as suggested here .

Also, if you are not doing anything special about your properties, @Akram Shahda's answer is a good suggestion

+3
source

Your personal and public name will be the same.

change the name of your personal name as

  int _submissionId; int _custId; int _broId; int _coverage; 

if you are using visual studio 2008 or later try

  public int SubmissionId { get; set; } public int CustId { get; set; } public int BroId { get; set; } public int Coverage { get; set; } 
+1
source

You have named a field and property with the same name that causes the error. You can rename the field, for example, to submitId. By the way, in this case there is no need to define a field. Use this property syntax:

 public int SubmissionId { get; set; } 
+1
source

In this case, you have a field and a property with the same name, this is not allowed.

The implementation of the standard storage will be as follows.

 private int _CustID; public int CustId { get { return _CustID; } set { _CustID= value; } } 

If you just use "Properties" without get or set logic, use automatic properties.

 public int CustID {get;set;} 
+1
source

Ya, anyone, as in the u code, declared each of SubmissionId, CustId, BroId, Coverage twice to the right twice. Why is that? u can directly declare the property below. Delete the first ad.

0
source

All Articles