|
Well, you could start by assigning the result of the subtraction to a variable, rather than just throwing it away:
TimeSpan diff = dtArray1[index].Subtract(dtArray1[index - 1]); And then you could use the value it generated...
The only instant messaging I do involves my middle finger.
English doesn't borrow from other languages.
English follows other languages down dark alleys, knocks them over and goes through their pockets for loose grammar.
|
|
|
|
|
i did it this way but my result is again 10.10.2015 instead of being 5 years
|
|
|
|
|
I seriously doubt you did exactly what Griff said. Your datatype is a DateTime (that's what 10.10.2015 represents) - this is completely different to a TimeSpan .
|
|
|
|
|
hmmm what u suggest me to do?really i dont know how to solve this problem
|
|
|
|
|
I think the problem is that you can't really explain the problem. If you can't explain the problem, this means you don't fully understand it. If I have a problem like this, I generally start off by breaking the problem down into things I know, and things I'm making as assumptions. By separating this list out, I tend to find I get a better understanding of what's actually being asked.
You keep showing code snippets with vague attempts at solutions, but this is leading us to make assumptions about what you are asking. You need to stop and present the real problem first - then, once you have worked this out, you would break it down further and start looking at code. For instance, you keep talking about years without intersection - but the examples you show effectively just look to work out the difference between the oldest and newest dates. The two things are not the same. Consider this example:
Start End
1995 2005
2000 2003
1998 2004 The dates that don't overlap are from 1995 to 1998 and 2004 to 2005. So, the total none overlapping years is actually 4 years. As you can see - your use of the term "years without intersection" adds confusion to the situation, so you really need to clarify this before we can continue.
|
|
|
|
|
no i understand my question but my problem is that i cant explain it ti your ,i want i find lenght of years
if there is overlap years i should delete one of them such as here
Start End
1995 2005
2000 2003
1998 2004 so for my question 2000 subtract 1995 and 2000-2003 is inside 1995-2005 so dont select it and also 1998-2004 inside in 1995-2005 i dont choose this years also so my totals years should be 2005-1995=10 my real question is that but how to do it i dont know
|
|
|
|
|
Don't start off by trying to think in code. Break the problem down using pen and paper. As a hint, you need to extract out the minimum start date and the maximum end date as a first step - only then can you start to remove the overlapping periods.
|
|
|
|
|
|
look at the value generated by the Subtract: it's not a DateTime, so you aren't using it.
Think about it: what do you get if you subtract one date from another? It can't be a date, because it doesn't have a reference point in time any more. It's a duration, or (in .NET speak) a TimeSpan.
Look at the TimeSpan structure[^], and you should find what you need in it's properties. Unless you want years or months, of course - because those require a reference point as well since they aren't all the same length.
If that's what you need, then try looking at this: Working with Age: it's not the same as a TimeSpan![^]
The only instant messaging I do involves my middle finger.
English doesn't borrow from other languages.
English follows other languages down dark alleys, knocks them over and goes through their pockets for loose grammar.
|
|
|
|
|
hi,
i have a dll and i wanted to copy this dll to application folder and add refrence of DLL. Then
Create Object for the CLass DLL
call the function sendsms with parameter
(username, password, senderid, mobnum, message, smsroute).
I have values for this parameters to pass. How to do that?
|
|
|
|
|
Depends on whether this is an activex dll or a .Net dll.
If its Activex, you need to import it - Importing and Extending ActiveX Controls in .NET[^].
.Net dll - just add reference, select this dll, instantiate this class and you will have access to public methods.
|
|
|
|
|
If the DLL contains a class, you need an extra step to call its member functions: You can create a wrapper class that creates one instance of the DLL's class on initialization, and frees it when done.
Calls to the wrapper-class methods just forward that call to the method of the same name in the single DLL-class instance.
To access the DLL, use (for example) this type of declaration:
[DllImport("ComGUIProxy.dll", EntryPoint = "InitializeContainer")]
public static extern bool InitializeContainer(int hContainer, int TicketID);
And put the DLL in the same folder as your executable.
|
|
|
|
|
plz help me how to create installer for windows application
|
|
|
|
|
|
|
|
string laceStrings(const string& s1, const string& s2)
{
if (s1.empty())
return s2;
if (s2.empty())
return s1;
string laced;
laced.resize(s1.size() + s2.size());
int i = 0, pos = 0;
int size = std::min(s1.size(), s2.size());
for ( ; i < size; ++i)
{
laced[pos++] = s1[i];
laced[pos++] = s2[i];
}
if (s1.size() >= s2.size())
for ( ; i < s1.size(); ++i)
laced[pos++] = s1[i];
else
for ( ; i < s2.size(); ++i)
laced[pos++] = s2[i];
return laced;
}
|
|
|
|
|
Sorry, but that's not how it works. We're not here to do your work for you. We'll help if you've got a specific question or problem.
|
|
|
|
|
{
("Let me see your code sir");
}
|
|
|
|
|
Adding to Dave's comment, you are asking a question about C++ and Python in a C# forum. That's not very clever.
|
|
|
|
|
|
Next time use Google & find write forum before posting questions.
Found this one[^] from Github. And alternatively you could Code Rewrite[^]
|
|
|
|
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication2
{
class Program
{
static void Main(string[] args)
{
List<DateTime> dtArray1 = new List<DateTime>();
List<DateTime> dtArray2 = new List<DateTime>();
Console.WriteLine("START Enter date");
for (int i = 0; i <= 2; i++)
{
string sStartdate1 = string.Empty;
sStartdate1 = Console.ReadLine();
DateTime dStartDate1;
if (DateTime.TryParse(sStartdate1, out dStartDate1))
{
dtArray1.Add(dStartDate1);
}
}
foreach (var item in dtArray1)
{
Console.WriteLine(item);
}
Console.ReadLine();
Console.WriteLine("end Enter date");
for (int j = 0; j <= 2; j++)
{
string sStartdate2 = string.Empty;
sStartdate2 = Console.ReadLine();
DateTime dStartDate2;
if (DateTime.TryParse(sStartdate2, out dStartDate2))
{
dtArray2.Add(dStartDate2);
}
}
foreach (var item in dtArray2)
{
Console.WriteLine(item);
}
Console.ReadLine();
}
}
}
|
|
|
|
|
|
int[] id1 = { 44, 26, 92, 30, 71, 38 };
int[] id2 = { 39, 59, 83, 47, 26, 4, 30 };
IEnumerable<int> both = id1.Intersect(id2);
foreach (int id in both)
Console.WriteLine(id);
/*
This code produces the following output:
26
30
*/
but how to compare with their index ,i mean i should compare id1[index0] with id2[index0] and each index if there will be intersection show result and of course result will be 0 because there not intersection with their index
|
|
|
|