|
Try:
DateTime Date1 = new DateTime(2014, 01, 10);
DateTime Date2 = new DateTime(2014, 10, 30);
TimeSpan diff = Date2 - Date1;
Console.WriteLine(diff.TotalDays);
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
|
|
|
|
|
Assuming you want ... given two dates ... to generate a data structure that contains each Month from the starting date to the ending date, and, for each month, the number of days in the month:
using System.Globalization;
private DateTimeFormatInfo dtf = new DateTimeFormatInfo();
private Dictionary<string, int> getMonthDays(DateTime d1, DateTime d2)
{
int nMonths = ((d2.Year - d1.Year) * 12) + d2.Month - d1.Month - 1;
var dctMonthDays = new Dictionary<string, int>();
for (int i = 0; i <= nMonths; i++)
{
int daysInMonth = DateTime.DaysInMonth(d1.Year, d1.Month);
string monthName = dtf.GetMonthName(d1.Month);
if (i == 0)
{
dctMonthDays.Add(monthName, daysInMonth - d1.Day);
}
else if (i == nMonths)
{
dctMonthDays.Add(monthName, d2.Day);
}
else
{
dctMonthDays.Add(monthName, daysInMonth);
}
d1 = d1.AddMonths(1);
}
return dctMonthDays;
}
DateTime d1 = DateTime.Now;
DateTime d2 = d1.AddMonths(7);
var monthDayDiff = getMonthDays(d1, d2);
foreach (var kvp in monthDayDiff)
{
Console.WriteLine("Month: {0} Days: {1}", kvp.Key, kvp.Value);
}
« I am putting myself to the fullest possible use which is all, I think, that any conscious entity can ever hope to do » HAL (Heuristically programmed ALgorithmic computer) in "2001, A Space Odyssey"
|
|
|
|
|
PoolGameSingle poolgame = new PoolGameSingle();
var cue = poolgame.CueStick;
Body CueStickBody = BodyFactory.Instance.CreateRectangleBody(physicsSimulator, 15, 15,1);
CueStickBody.Position = new Vector2(902, 250);
cue = CueStickBody;
Geom CueStickGeom = GeomFactory.Instance.CreateRectangleGeom(physicsSimulator, CueStickBody, 15, 15, 20);
CueStickGeom.CollisionGroup = 1;
CueStickGeom.RestitutionCoefficient = .8f;
CueStickGeom.FrictionCoefficient = 0
|
|
|
|
|
You have already posted the same question on StackOverFlow and GameDev, but why not also post the question on the FarSeer Discussion forum: [^].
« I am putting myself to the fullest possible use which is all, I think, that any conscious entity can ever hope to do » HAL (Heuristically programmed ALgorithmic computer) in "2001, A Space Odyssey"
|
|
|
|
|
If I wanted to post the question on that page, I would have done so long ago.. But nobody is replying me.
|
|
|
|
|
Member 10948508 wrote: If I wanted to post
Member 10948508 wrote: I would have done so
Member 10948508 wrote: But nobody is replying me.
Possibly, the latter is because of the first two?
You don't generally get replies to messages you haven't posted...
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
|
|
|
|
|
I know what you mean, OG; I get messages to replies I never made: those are the ones that really bother me !
« I am putting myself to the fullest possible use which is all, I think, that any conscious entity can ever hope to do » HAL (Heuristically programmed ALgorithmic computer) in "2001, A Space Odyssey"
|
|
|
|
|
And I get answers to questions nobody ever asked.
Called "adverts", on TV...
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
|
|
|
|
|
Perhaps, as they are the experts in this, you might want to give them a try. Your answer is the same as going to a DIY store and saying "I have a toothache, how do I get rid of it?" and when someone tells you to go see the dentist, you reply that if you'd wanted to do that, you would have, but your toothache is still there. Can you see how absurd the position is?
|
|
|
|
|
What? Ask the people who know the most about it?
But they might suggest he RTFM!
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
|
|
|
|
|
Hello. I have this small video application which uses some threads. Now when a thread is called to open the media player for a media file, an exception is thrown
COM object that has been separated from its underlying RCW cannot be used
What does this exception mean and how can I fix this issue? Thanks for any pointer.
|
|
|
|
|
|
Creaze the COM object in the main thread and use it only there!
|
|
|
|
|
public abstract class NoImplementations
{
public abstract void DoSomething(int arg1, string arg2);
public abstract int SomeInt { set; get; }
public NoImplementations()
{
SomeInt = 34;
}
}
private class sonOfNoImplementation : NoImplementations
{
public override void DoSomething(int arg1, string arg2)
{
}
public override int SomeInt { get; set; }
}
sonOfNoImplementation sonOfNI = new sonOfNoImplementation();
int x = sonOfNI.SomeInt;
I am baffled I can "get away with this."
Appreciate your thoughts !
« I am putting myself to the fullest possible use which is all, I think, that any conscious entity can ever hope to do » HAL (Heuristically programmed ALgorithmic computer) in "2001, A Space Odyssey"
|
|
|
|
|
|
|
Basically, I agree, but it's important to understand: this is rationale, not the syntax rule.
Also, it does not address Bill's issue: actually, there is absolutely nothing wrong with having non-virtual method of an abstract class. I explained in my comment below why it is often be important.
—SASergey A Kryukov
|
|
|
|
|
Sergey Alexandrovich Kryukov wrote: Also, it does not address Bill's issue
Which would be why I marked it as a suggestion, rather than an answer.
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
All right, it's perfectly fine, I just took a note without any negative connotation.
Please see the comments by Richard MacCutchan and myself. I explained in detail why Bill's code is perfectly fine and safe (just updated).
—SASergey A Kryukov
|
|
|
|
|
You can "get away with it" because abstract classes can't be instantiated.
And because the concrete classes derived from it must implement both the setter and getter properties in order to compile, the abstract constructor can be guaranteed that the property is implemented in all instances.
So it's legal, and will work!
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
|
|
|
|
|
It makes perfect sense. I just changed my comment to the wrong Mehdi's post and stated: abstract class is not a placeholder, not even close. I explained what it is and what is its purpose. And it should add: it should not be used as a substitute of interface.
Having non-abstract methods in an abstract class has more than perfect sense. Such methods are inherited and can be used in derived classes (so they should better be protected). Internal and public methods are even more important: the compile-time type of abstract class is usually used as a base class for some hierarchy of terminal derived classes used in polymorphic set. This is how you work with derived classed: through members of the base class. If such base class method uses virtual methods, late binging mechanism dispatch the calls to the methods of derived classes, so the whole OOP mechanism is leveraged.
There are many cases when this method in abstract class need not to be overridden, therefore, there is no a need to make it virtual or abstract (all abstract methods are of course virtual).
This is the very basic approach in OOD every developer should know and use.
[EDIT]
Now, let me explain why there is no danger in your assignment of the abstract property in a non-abstract (and even non-virtual) method NoImplementations :
This is an instance method. As an instance method, it will need an instance to be called on. Such instance will always be an instance of some derived non-abstract type, because an abstract type won't allow to get an instance. And, such non-abstract type could not be created if SomeInt is not given the implementation. The mechanism of the late binding will use the virtual method table for the setter of SomeInt , according to the runtime type of that non-abstract derived type. Therefore, in all cases where NoImplementations can be called, the setter of SomeInt can also be correctly called and actually assign the property value. No problems whatsoever.
—SASergey A Kryukov
modified 10-Nov-14 17:39pm.
|
|
|
|
|
Countered Univote.
What do you get when you cross a joke with a rhetorical question?
---
The metaphorical solid rear-end expulsions have impacted the metaphorical motorized bladed rotating air movement mechanism.
|
|
|
|
|
Counter countered.
That's how democracy works
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
Yes, as soon as you ready to agree with your role of the person which wrong action can be compensated by other public.
You did not even explain your opinion.
Voter always right?
—SASergey A Kryukov
|
|
|
|
|
Sergey Alexandrovich Kryukov wrote: You did not even explain your opinion. You don't get an explanation with each vote.
Sergey Alexandrovich Kryukov wrote: Voter always right? Ehr, again; "no".
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|