Naming Convention for Model Properties? [closed] - c#

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 4 years ago.
Improve this question
If you have an int that represents days, what would be the best way for its name:
MinLimitInDays?
MinLimitwith "in days" as xml doc comment?
or the same with a double:
ProductRevenueInPercentage
ProductRevenue with "in percentage" as xml doc comment?
Or would you even create a new class with a specific constructor e.g. MinLimit(int days) that has a property int days?

MSDN states that you should value readability over brevity.
So:
int MinLimitInDays = 4;
Would be better represented as:
int MinimumAmountOfDays = 4;
Better yet, save it as a TimeSpan
TimeSpan MinimumLimit = TimeSpan.FromDays(4);
With everything else, if you're not sure, make it more verbose.
double ProductRevenuePercentage;
is better than:
double ProductRevenue;
which could be the overall revenue. Don't be afraid of making properties too long, and don't abbreviate unless the abbreviation is ubiquitous.

Related

What is the 'Subtract Days' equivalent of DateTimePicker.Value.AddDays()? [closed]

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 4 years ago.
Improve this question
I have a DateTimePicker and two buttons on a form. The buttons are intended to allow a user to cycle backwards and forwards through the dates displayed in the picker.
The code DateTimePicker.Value.AddDays(1); increments the value displayed and DateTimePicker.Value.AddDays(-1); decrements it. It seems a bit clunky to me but this works as expected, is passing in a value of -1 the correct way to decrement the displayed date?
Why isn't there a SubtractDays() method?
As you've seen, you can use AddDays with a negative amount to subtract days, so there's no need for the extra methods (there would need to be one for each of the Add methods). If it really bothers you, you can write extension Subtract methods for all the Add methods.
For example
public static class DateTimeExtensions
{
public static DateTime SubtractDays(this DateTime start, int days)
{
return start.AddDays(-days);
}
}

Convert.ToInt32("example") Collisions? [closed]

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 5 years ago.
Improve this question
Will the C# function Convert.ToInt32(text) convert different words to the same int? Any links or pushes in the right direction are appreciated!
P.S.
What about anagrams?
No, Convert.ToInt32(text) will just try to parse your text to an int, like:
Convert.ToInt32("032") will return 32 as int but
Convert.ToInt32("Brian") will throw an exception.
I assume that you want to have some kind of hashing, when you say "different words to the same int".
Try GetHashCode(). It will return the same value if you call it multiple times with the same value, for example:
"Brian".GetHashCode() will always return 1635321435

What does (int) mean in c#? [closed]

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 6 years ago.
Improve this question
I've encountered sometimes code like this and I am kind of new to programming. I want to find out what's the meaning behind those objects or data type enclosed in parenthesis.
(int)
(datagridview)
(form)
If you see something like this it's called a cast. It's used to explicitly convert a data type to another data type.
double pi = 3.14159;
int my_int = (int)pi;
See this description on casting for more details.

What's the equivalent of Delphi's RoundTo() in C#? [closed]

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 7 years ago.
Improve this question
What's the equivalent of Delphi's RoundTo() in C#?
I am not very familiar with Delphi and I am aware of C#'s Math.Round() but am not sure how equivalent they are. Math.Round() has several overloads and RoundTo() has two.
The equivalent method is Math.Round. You need to use the overload which offers the functionality that you need, whatever that is.
The Delphi RoundTo function is not overloaded and is best matched with this overload of Math.Round:
public static double Round(
double value,
int digits
)

Comma-Separated String to Double C# [closed]

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 want convert 1,2,3,4,5,6,7,8,9,10 String to Double.
I tried Convert.ToDouble(String); and Double.Parse(String); but returned 1.0
How to convert multi comma string to double?
Thanks for help.
From the looks of your question you actually have 10 numbers not 1. Use this code:
var nums = "1,2,3,4,5,6,7,8,9,10";
var digits = nums.Split(',').Select(r => Convert.ToDouble(r)).ToArray();
// the result will be an array of doubles, also this only works with .NET 3.5 or better.
Let me know if this works for you.

Categories

Resources