I have a struct lying in a class as below. I think that that is not good. Struct should be separate a file, however, in this case, this struct is only use in a class. Please help me a idea about that: how best practice for C# struct?
class StudentMangement
{
private struct Student
...
Are my constants defined in the correct location in my Model class's implementation file?
It is impossible to tell. Where a variable needs to be declared is entirely dependent upon its intended scope.
If a variable is used only within a single block (within an if, else, or loop, or anyt...
For us to really answer this question, you really need to add some of the code from the class's methods that actually use the struct. — nhgrif38 secs ago
This script is a total of 99 lines. Of that, 49 lines are insulting, annoying, and ironic self-congratulating comments.
In general, comments are good. They help any future maintainer (including yourself when it's been 6 months since the last time you looked at the script) to understand what ...
There's not a lot to go on here, but consider this. Can someone's age be -10? Will a student ever be 1000 years old? An int can be both of these values. That means a simple default getter/setter isn't sufficient. You'll need to write some bounds checking in the setter and throw an exception if so...
I've upvoted your answer, but I still think the question should be closed as unclear.
Because from recent meta discussions, we've sort of established that...
1. Context is important. 2. The plain-English part matters. 3. The posted code and the plain-English part should match up.
If we ignore the plain-English part, we can comment about the problems with age using a default setter. We could even comment about the fact that this class is completely useless as it only contains a private struct (so we can't use that struct, etc)
A struct within a class, and this is the edit history: http://codereview.stackexchange.com/posts/60534/revisions
The original code include this method:
public bool AddStudent(string name, int age, string grade)
{
// To do something
}
None of the code in the snippet provided uses this meth...
You should elaborate on how and why the struct in the question violates 1 or more of these points. It doesn't seem particularly obvious to me. — nhgrif8 mins ago
How is it mutable? Could it be made immutable?
I'm not familiar with C# at all.
And you can't put Objective-C objects in structs in ARC.
A struct within a class, and this is the edit history: http://codereview.stackexchange.com/posts/60534/revisions
The original code include this method:
public bool AddStudent(string name, int age, string grade)
{
// To do something
}
None of the code in the snippet provided uses this meth...
Okay, so this struct would be okay if it just didn't expose the setters?
(and if it weren't a private struct in a class with nothing else in it)
> Does Student represent a single value, similar to primitive types? Again, no. Things that would match this criteria include coordinates, rectangles, colours, etc.
not quite: a struct should also be valid for all default values, so a Student with string.Empty for a name and age 0 in grade string.Empty would have to be valid.
@nhgrif i took those examples from msdn.microsoft.com/en-us/library/0taef578.aspx "The struct type is suitable for representing lightweight objects such as Point, Rectangle, and Color."
private struct Student
{
public string Name { get; set; }
public int Age { get; set; }
public string Grade { get; set; }
public void SetGrade(string grade)
{
this.Grade = grade;
}
}
var students = new[] { new Student { Name = "bobby tables", Age = 23 } };
foreach (var student in students)
{
student.SetGrade("A+++");
}
Console.WriteLine(students[0].Grade);
The problem with that question isn't that it's unclear.
class StudentMangement
{
private struct Student
{
public string Name { get; set; }
public int Age { get; set; }
public string Grade { get; set; }
}
}
That edit removes a piece of noise, that could hav...
I am working in level set method, specially Lankton method paper. I try to implement Histogram Separation (HS) Energy problem (Part III.C). It based on Bhattacharyya to control the evolution of contour. To understand it, the first we consider global method in which given an input image and a cont...
I was asked to modify existing code to allow multi-level page structure. Each page can have one parent, and one page can have multiple children.
I will present following code. My question is is there a more efficient way of doing this? I am hard-coding the number of levels that are reachable.
...
I can't help but question everyone's sanity on this page, as this function really has no business being any longer than this:
def is_ok(user_dbs, self_db):
return not user_dbs or (len(user_dbs) == 1 and user_dbs[0].key == self_db.key)
@Will Users in this room are more likely to get votes than those who aren't ;)
"I would stick to C89" - NO! There is no good reason for not using the nice things C99 or C11 gives you, besides being able to use the crappy Visual Studio C compiler (which does support some C99 features anyways). — syb0rg2 days ago
@Will Every now and then I'll get into an argument with someone that it's more efficient to declare variables above their loops. Freaking people stuck in 1980... x.x
The signal to noise ratio has always been pretty terrible with C, I'm afraid. It's amazing how wide-spread terrible, archaic practices can be with widely used languages (C++ too). It's depressing :(. Thankfully though, the world seems to be waking up with regards to C++, and to a lesser extent C. Or maybe I've just pulled my head out of the sand -- no idea.
Hah. At least it's not "JAVA NO WORK NEED HELP FIX"
Every time someone writes "JAVA", god kills 3 kittens.
I can't help but question everyone's sanity on this page, as this function really has no business being any longer than this:
def is_ok(user_dbs, self_db):
return not user_dbs or (len(user_dbs) == 1 and user_dbs[0].key == self_db.key)
Oh noes, I have The Whiteboard in my "other rooms" feed... so dirty...
I saw the f+++ word posted multiple times in a 2 minute span... also something about optimizing your wifi for a large software patch all the while not disrupting downloads of... you-know-what... and beer.
On Code Golf is is common to see a king-of-the-hill question where you have to implement an AI based on the rules given in the question.
So then I got to thinking - "If I developed an AI for one of these 'games', I could post it on Code Review to improve it!" But then I was wondering how an AI ...
> Starting today, all existing FiOS Internet customers can upgrade to our entry level FiOS Quantum tier of 50/25 Mbps tier for just $10 more a month and keep the speed for as long as they wish. - See more at: newscenter.verizon.com/residential/news-articles/2013/…
I am in a Motorcycle ministry and want to go to Bike Blues and BBQ but need to have the funds to get me and at least another guy down there and back. somewhere around $500
I feel a little sad that my automagically zombie answer is sitting there at -1 ... show some love anyone? I think vogel forgot to re-upvote after he misread it...
Are there still any places where you can walk up to the counter, hand the tender an empty case from the display shelf, tell them you want to rent this movie?