Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
I am writing a sudoko program, I want the user to edit certain values in the array,but not the values which are already there. how do I initialize the array?
The easiest way to overcome your problem is to use 2 multidimensional arrays, the first one to save the value and the second one to check whether some cell can be edited by the user or not..
int[,] ValueArray= new int[4,4];
boolean[,] EditedArray= new boolean[4,4];
You can approach your problem with multiple solutions, all of which relay on the same principle -> Having your number coupled with a boolean.
You can write it down with a class:
public class SudokuCell
{
public bool IsEditable { get; set; }
private int _value;
public int Value
{
get { return _value; }
set { if (IsEditable) _value = value; }
}
or a struct:
public struct SudokuCell
{
public bool IsEditable;
public int Value;
}
and have a List or an Array of SudokuCells that you can use as your data structure or you can use a lazier method and write it down using Tuple:
List<Tuple<int, bool>> sudokuCells = new List<Tuple<int,bool>>();
Then whenever you want to change the value you can check it's corresponding bool and you instantly know whether you can or can't change it (assuming you set it when you initialize your sudoku)
Your sudoku user edits your UI, not your array. Make the UI element read-only when the associated data should be read-only.
Related
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 months ago.
The community is reviewing whether to reopen this question as of 7 months ago.
Improve this question
I have just looked at an example from Microsoft Social Network on how to use Application Settings namely this one:
public bool IsUSer(SettingsProperty Setting)
{
bool flag = Setting.Attributes[typeof(UserScopedSettingAttribute)] is UserScopedSettingAttribute;
bool flag1 = Setting.Attributes[typeof(ApplicationScopedSettingAttribute)] is ApplicationScopedSettingAttribute;
if (flag && flag2)
{
throw new ConfigurationErrorsException(SR.GetString("BothScopeAttributes"));
}
if (!flag && !flag2)
{
throw new ConfigurationErrorsException(SR.GetString("NoScopeAttributes"));
}
return flag;
}
This checks to see if the Setting is both User and Application Scoped or neither. Is it even possible that these two situations can occur. Surely the API would not allow this to happen in the first place. Should we be checking for this or is this example a little over the top. I know this is more a discussional rant but really, surely this can't really happen?
Link to Example: https://social.msdn.microsoft.com/Forums/en-US/4c0d2eae-2f0b-41c8-bb60-c4b0ffd3cd0b/how-to-retrieve-usersettings-v-defaultsettings-c-vbe2008?forum=netfxbcl
Thanks
Danny
[UserScopedSetting] and [ApplicationScopedSetting] are attributes so you might use them like this:
public class MyUserSettings : ApplicationSettingsBase
{
[UserScopedSetting()]
[DefaultSettingValue("white")]
public Color BackgroundColor
{
get
{
return ((Color)this["BackgroundColor"]);
}
set
{
this["BackgroundColor"] = (Color)value;
}
}
}
(Source for above code)
If you refer to this question, you'll see that it isn't possible to prevent two attributes occurring together. So, the code you have shown is actually protecting against one of these two scenarios:
1 - Both attributes are applied:
public class MyUserSettings : ApplicationSettingsBase
{
[UserScopedSetting()]
[ApplicationScopedSetting()]
[DefaultSettingValue("white")]
public Color BackgroundColor
{
get
{
return ((Color)this["BackgroundColor"]);
}
set
{
this["BackgroundColor"] = (Color)value;
}
}
}
2 - Neither attribute is applied:
public class MyUserSettings : ApplicationSettingsBase
{
[DefaultSettingValue("white")]
public Color BackgroundColor
{
get
{
return ((Color)this["BackgroundColor"]);
}
set
{
this["BackgroundColor"] = (Color)value;
}
}
}
So ultimately it is checking that exactly one of these two attributes is applied.
Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 3 years ago.
Improve this question
so in my little c# console-program, i have i have this class, where I use get and set methods for my properties
class myClass
{
public int ID { get; set; }
public string value { get; set; }
public myClass(int ID, string value)
{
this.ID = ID;
this.value = value;
}
}
however when i am im my main method, i am not able to access these two properties through the get-method, neither am i able to use set() on any of them, what am I doing wrong?
In C#, you don't need to invoke the getter or setter on a property:
var id = class.ID; // getter invoked automatically
Will automatically call the getter, and in your example, you're already using the setter in your constructor.
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 7 years ago.
Improve this question
I am creating ad hoc reporting solution, so I came up with a this method, its added in WCF service which will be called from front end client,
GetEmployeeDetails(int id, bool includeAddressHistory, bool
includeSalaryHistory, bool includePositionHistory, bool
includeProjectHistory, ...never ending list)
Now issue is I need to get all of the data based on filters and then either return the complete dataset or return it as a stream, as I have another method which returns same dataset as a stream,
Usually, when you need to pass a rather large number of parameters (regardless of their type), it's time to consider parameter object:
// this is just POCO
public class SearchParameters
{
public string SomeString { get; set; }
public DateTime? SomeDate { get; set; }
public bool? SomeBool { get; set; }
// etc...
}
IEnumerable<SomeEntitites> GetSomeEntitites(SearchParameters searchParameters);
Note, that for constructor cases the solution could be a builder pattern.
An alternative if things get even more complicated is to have one class that has the EmployeeDetailsRequestParameters defined. This is particularly useful if you also do things like filtering and have a lot more than just what can fit into a flag enumerable.
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
I'm sorry if the title's a bit unusual or wrong, I'm not certain about how to ask this. Please offer an edit or change it if so.
I'm trying to achieve this:
private class Products
{
public Status
{
// set status to `Active`, `Deleted` or `Suspended` for an instance of Products. //
}
}
What I don't know how to do is code something that will allow me to call Products.Status.Active, then set that value to MyAccount. The other two values will be Suspended and Deleted.
You need to make Status an enum
public enum Status
{
Active = 1,
Suspended = 2,
Deleted = 3
}
Looks like you want to implement ChangeStatus as static
public class TaskClass
{
public static ChangeStatus(Accounts.Account a, MyTask t, Status s)
{...}
}
private void Main() {
Accounts.Account account = new Accounts.Account();
TaskClass.Task task = new TaskClass.Task();
TaskClass.ChangeStatus(account, task, Status.Active);
}
PS If you need to name it TaskClass.Status instead of Status, just nest the enum inside TaskClass.
Closed. This question is off-topic. It is not currently accepting answers.
Want to improve this question? Update the question so it's on-topic for Stack Overflow.
Closed 9 years ago.
Improve this question
There is a public interface in the project with a value as follows:
Name3D MyName3D { get; set; }
Now in another location I am using a public sealed class, I added the namespace / using System.Interfacename. Now I want to set it like follows:
private readonly Interfacename m_MyName3D ;
private const string 3DName = ##;
How would i go aobut setting it up so ## is the value of MyName3D. Again I haven't done anything like this before. Just wanted to give it a try?
Would be really appreciated if I could get some detail onto how it works.
Update One
Do you mean this?
using Interfacename;
public sealed class InfoController : AsyncController
{
private readonly Interfacename m_MyName3D ;
private const string 3DName = ##;
You can not assign anything to a const member at runtime. You can however make 3DName a readonly property and relay the get accessor to the interface:
private string 3DName { get { return m_MyName3D.MyName3D; } }
But maybe I did not get what you are trying to do, if so please describe it more clearly.
edit: you are using two types for 3DName, Name3D and string. If Name3D has no conversion operators you need to use it throughout the property.
private Name3D 3DName { get { return m_MyName3D.MyName3D; } }
If you really need to return a string the you need to write a string conversion operator for Name3D:
struct/class Name3D
{
public static implicit operator string(Name3D name)
{
return name.whatever; // this needs to be the data holding member(s) of Name3D
}
}