Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 4 years ago.
Improve this question
class staff:schoolMember
{
private int _Salary=60000;
public int getSalary();
{
return _Salary;
}
public void setSalary(int e)
{
_Salary=e;
}
}
This is part of my C# code, and an error occurs at line 2 and I'm not sure what this error means, and I don't see the error in my code. Please help! Thankyou!
remove ; after getSalary()
and make _Salary type consistent with SetSalary() parameter type
class staff : schoolMember
{
private int _Salary = 60000;
public int GetSalary()
{
return _Salary;
}
public void SetSalary(int e)
{
_Salary = e;
}
}
Related
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 2 years ago.
Improve this question
Here is my code
I tried removing the public but it just shows more errors
It shows The modifier public/private is not valid for this item
public string GetPlayerSide();
{
return "?";
}
public void EndTurn();
{
Debug.Log("EndTurn is not implemented!");
}
}
You have to remove ';'
Incorrect version:
public void EndTurn();
Correct version:
public void EndTurn()
Complete code:
public string GetPlayerSide()
{
return "?";
}
public void EndTurn()
{
Debug.Log("EndTurn is not implemented!");
}
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 2 years ago.
Improve this question
I'm new to C# and i'm trying to encapsulate certain states in an enum and trying to add them to a list but I am getting an error missing ;
Here is what I have coded out:
namespace abc.Models
{
public enum GroupState
{
FINISHED,
SKIPPED,
ERROR
}
public static class GroupStates
{
public static List<GroupState> TerminalStates = new List<GroupState>{
GroupState.FINISHED, GroupState.SKIPPED, GroupState.ERROR
}
}
}
I intend to use these states in my controller file. What am I doing wrong here?
You are missing a semicolon ; after the statement
public static List<GroupState> TerminalStates = new List<GroupState>{
GroupState.FINISHED, GroupState.SKIPPED, GroupState.ERROR
}
and "ERROR" is not in your enum "GroupState" it is ERROR3. Both changes need to be added:
Code snippet will be like:
public static class GroupStates
{
public static List<GroupState> TerminalStates = new List<GroupState>{
GroupState.FINISHED, GroupState.SKIPPED, GroupState.ERROR3
};
}
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 5 years ago.
Improve this question
This is my generic Container class:
public class Container<T> : IContainer<T> where T : BaseModel, new()
{
private string include;
public Container()
{
}
public Container<T> Include(Expression<Func<T>> property)
{
include = GetMemberName(property);
return this;
}
}
Now I want to set the include value like this:
var container = new Container<TestClass>();
// doesn't work
container.Include(x => x.SomeProperty);
// also doesn't work
container.Include(() => TestClass.SomeProperty);
And as result the include should habe the value SomeValue. I also tried a parameterless Function, in the latter case VS says it's missing an object reference for the non-static property.
I got the GetMemberName from this thread: [Retrieving Property name from lambda expression
Change your func definition:
public Container<T> Include(Expression<Func<T, object>> property)
{
include = GetMemberName(property);
return this;
}
This is the correct usage:
container.Include(x => x.SomeProperty);
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 8 years ago.
Improve this question
I'm already aware that there are many other similar questions regarding this topic, however looking at the answers and adapting my code in relation to those has proved unsuccessful.
The code below is part of my Artist class, where I use CompareTo to compare between the artist name and the artist name (obj) passed in..
class Artists : IComparable
{
private string artistName;
private string artistMembers;
public int CompareTo(Object obj)
{
Artists otherArtist = (Artists)obj;
return artistName.CompareTo(otherArtist.ArtistName);
}
public Artists(string artist, string members){
ArtistName = artist;
Members = members;
}
public string ArtistName
{
set { artistName = value; }
get { return artistName; }
}
public string Members
{
set { artistMembers = value; }
get { return artistMembers; }
}
}
I really want to avoid making the variables public, which is a solution offered elsewhere, so I was wondering what I need to do to sort this problem out, and what I am doing wrong so I can learn from mistakes.
Thanks in advance.
EDIT 2
Closed VS and recompiled, and suddenly worked. Sorry for time wasting.
I'm assuming from your error that CompareTo is not public in your real code. Implicit interface implementations must be public.
You could implement the interface explicitly, and then clients would have to cast to IComparable to see the method:
int IComparable.CompareTo(Object obj) // will be private unless explicitly using the interface
{
Artists otherArtist = (Artists)obj;
return artistName.CompareTo(otherArtist.ArtistName);
}
Artists a1 = new Artists("Beatles", "Paul, Ringo");
Artists a2 = new Artists("U2", "Bono");
// this will fail:
//int i = a1.CompareTo(a2);
// this will work:
int i = ((IComparable)a1).CompareTo(a2);
However note that your class is internal by default, so the class is not even public.
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 8 years ago.
Improve this question
When writing out a property in visual studio, the IDE autocompletes the wrong text and interrupts my flow.
class Person
{
private int age;
public int Age;
{
AppDomainSetup //
}
AppDomainSetup is given when I've typed set. Why is the IDE confused?
You should remove ; after "Age".
It is:
internal class Person
{
private int age;
public int Age { set; get; }
}
Try
internal class Person
{
private int age;
public int Age { set; get; }
}
The more complete answer is that you've ended the field Age and the IDE is reading what you've written and is expecting a Type (among a few other contextually based options, of which set is NOT one). You've only written set, and the best match for set for a type in the given context is AppDomainSetup because it is the first Type in whose name the substring set is found. The autocomplete behavior is to input the selected suggestion when you press space.
To correct this (or to stop confusing intellisense), don't put a colon after the property name.
public int Age { set // and continue typing