|
Thank you for your reply
I don't need the for example the last 4 latest records in the array... as I can have several days and the oldest date has 3 times it was altered creating 3 different files for that day... I would need the newest one.
|
|
|
|
|
I did read and understand your original post.
I'm not so sure you did read and understand any of my replies so far.
Anyway I have added yet another reply with the full code, albeit untested.
For me the subject is closed.
|
|
|
|
|
If the filename will always be in the format
name_yyyyMMdd_HHmm.extension
then you could use something like this (needs some [alot of] optimization but works). You can now implement a custom comparer to compare by name and if eqaul, compare by date.
public class MyFileData
{
private string fullname;
public MyFileData(string fullname)
{
this.fullname = fullname;
}
public string Fullname
{
get { return fullname; }
}
public string Name
{
get { return fullname.Substring(0, fullname.IndexOf('_')); }
}
public DateTime DateTime
{
get { return DateTime.ParseExact(fullname.Substring(fullname.IndexOf('_') + 1, 13), "yyyyMMdd_HHmm", CultureInfo.InvariantCulture); }
}
public string Extension
{
get { return fullname.Substring(fullname.IndexOf(".") + 1); }
}
}
DaveIf this helped, please vote & accept answer!
Binging is like googling, it just feels dirtier.
Please take your VB.NET out of our nice case sensitive forum.(Pete O'Hanlon)
BTW, in software, hope and pray is not a viable strategy. (Luc Pattyn)
|
|
|
|
|
So I created a dictionary DICTIONARY1
dicFilesDT.Add(dateParts[1], (dateParts[1] + dateParts[2] ));
so that I would have just the:
KEY as the Date and
VALUE as the Date+Time
I need help in making another dictionary (DICTIONARY2) that would
1. If there are no Duplicates from checking DICTIONARY2 using foreach keyvaluepair in DICTIONARY1 add Key Pair to DICTIONARY2
2. Check for duplicates of the Key (Date) (thinking ex. dictionary.ContainsKey)
if the dictionary has the KEY then
Compare the KEY VALUE from DICTIONARY 1 to DICTIONARY 2 to see which one is larger
ex. 230132 compared to 100425
if DICTIONARY1 KEY VALUE is larger Delete KeyValuePair from DICTIONARY 2 and add DICTIONARY 1 KEY VALUE
else do nothing and continue the loop
Thank you folks for helping me wiht this.
|
|
|
|
|
You're making it all way too complex. Here is what I would do (untested!):
string[] files = Directory.GetFiles(S.ImportFolder);
Array.Sort(files);
int count=files.Length;
for(int i=1; i<=count; i++) {
string curr=files[i-1];
string next="_the_end_";
if (i<count) next=files[i];
if (strcmp(curr.Substring(0,curr.LastIndexOf('_')), next.Substring(0,next.LastIndexOf('_'))!=0) {
}
}
Some nasty trick was used to make sure the last file is also included.
|
|
|
|
|
Hi Luc,
I tried the above code, just trying to debug the last line
if (strcmp(curr.Substring(0,curr.LastIndexOf('_')), next.Substring(0,next.LastIndexOf('_'))!=0) {
strcmp is a c++ concept, is that similiar to StringComparer?
also my ide complains !=0 that it cannot be applied to an int and a string. Tried playing around with the brackets and to no function.
let me know what I can do.
|
|
|
|
|
Sorry, my mistake, should not be strcmp, should be string.Compare
|
|
|
|
|
I have a list with 22 instances of this class in it:
public class aspnetRole
{
public Guid? RoleId { get; set; }
public Guid? ApplicationId { get; set; }
public string RoleName { get; set; }
public string Description { get; set; }
public bool IsGlobal { get; set; }
}
There are duplicate entries that I want to remove. I tried this:
List<aspnetRole> RolesNoDups = Roles.Distinct().ToList();
where Roles is the list and RolesNoDups would be the result.
When I run it there are still 22 items in RolesNoDups.
How do I do this?
Everything makes sense in someone's mind
|
|
|
|
|
I don't have Distint on my generate methods.
However, you will most likely need to write a comparer or override the equals method if your class if you want to get the results expected. After all aspnetRole is a class so two instances with the same values are not the same.
|
|
|
|
|
That's what I figured, but I was hoping for a simpler way.
Thanks
Everything makes sense in someone's mind
|
|
|
|
|
This MSDN page[^] says:
Returns distinct elements from a sequence by using the default equality comparer to compare values.
If you want to return distinct elements from sequences of objects of some custom data type, you have to implement the IEqualityComparer<T>[^] generic interface in the class.
DaveIf this helped, please vote & accept answer!
Binging is like googling, it just feels dirtier.
Please take your VB.NET out of our nice case sensitive forum.(Pete O'Hanlon)
BTW, in software, hope and pray is not a viable strategy. (Luc Pattyn)
|
|
|
|
|
|
In SQL database, I have role,process and menu table mappings for showing/hiding menu based on the logged on user's role.
I need to show/hide certain buttons in the application based on the roles and processes.
How do I do this? Please point in the right direction
------------------------------------------------------------
"The only true wisdom is in knowing you know nothing." --Socrates
|
|
|
|
|
In ASP.NET? WinForms? Using the standard roles/membership provider?
"WPF has many lovers. It's a veritable porn star!" - Josh Smith As Braveheart once said, "You can take our freedom but you'll never take our Hobnobs!" - Martin Hughes.
My blog | My articles | MoXAML PowerToys | Onyx
|
|
|
|
|
In ASP.net 3.5.
I have some roles which can't be in AD group. Need to put them in sql database.
------------------------------------------------------------
"The only true wisdom is in knowing you know nothing." --Socrates
|
|
|
|
|
Take a look at this[^] to get some information about ASP.NET membership and roles. Next time, try posting ASP.NET questions in the ASP.NET forum.
"WPF has many lovers. It's a veritable porn star!" - Josh Smith As Braveheart once said, "You can take our freedom but you'll never take our Hobnobs!" - Martin Hughes.
My blog | My articles | MoXAML PowerToys | Onyx
|
|
|
|
|
I want a dropdown menu to be visible only when i click on the text box.
Is this possible? I can find no such click event in asp.net
|
|
|
|
|
Think about this for a while and consider the postback model. You'd either have to postback to the server every time you clicked in the textbox which would cause the whole page to be refreshed, which would be a real pain for the user, or you have to find an alternative mechanism. Is this giving you a hint? Think of javascript - and it's not a click event you want to consider, it's the focus event.
"WPF has many lovers. It's a veritable porn star!" - Josh Smith As Braveheart once said, "You can take our freedom but you'll never take our Hobnobs!" - Martin Hughes.
My blog | My articles | MoXAML PowerToys | Onyx
|
|
|
|
|
YOUR_TEXTBOX_ID.Attributes.Add("onclick","Visible(true);");
function Visible(isVisible)
{
$get('your_dropdown_clientid').visible = isVisible;
}
|
|
|
|
|
Is there any efficiency lost in declaring variables inside loops, or is the compiler smart enough to optimize the code so the variable is really only reserved once? For example, would it be more efficient to move the variable declaratrions outrside of the loops?
Example 1
for (int i = 0; i < tblApplications.Controls.Count; i++) { ... }
Is it more efficient to write it like this:
int i;
for (i = 0; i < tblApplications.Controls.Count; i++) { ... }
Example 2
foreach (GridViewRow row in grdUsers.Rows)
{
string value= row.Cells[1].Text;
}
Is it more efficient to write it like this:
GridViewRow row;
string value;
foreach (row in grdUsers.Rows)
{
value= row.Cells[1].Text;
}
|
|
|
|
|
I think you'll find it makes no difference as far as efficiency is concerned - it's not going to declare the variables each time around the loop.
However, there is a difference. In your first example i goes out of scope when the loop finishes. In the alternative, i is still in scope when the loop finishes (with a value equal to the Count).
Regards
David R
---------------------------------------------------------------
"Every program eventually becomes rococo, and then rubble." - Alan Perlis
The only valid measurement of code quality: WTFs/minute.
|
|
|
|
|
There is no difference at the MSIL level. In both cases, the variable would get a named local variable slot.
|
|
|
|
|
Check your apps memory usage. Each declaration using more memory in .NET, even though it shouldn't
One interesting note, however:
foreach(string abc in someList){
}
string abc = "test";
Is a compiler error.
|
|
|
|
|
it is all the same. However
for (int i = 0; i < tblApplications.Controls.Count; i++) { ... }
is counting those Controls over and over, you may gain some by storing that in a local variable once.
|
|
|
|
|
The first form (declaring the variable with the loop) is more efficient in terms of memory, the scope of the variable stays within the loop, so when the loop ends, the variable is ready for garbage collection. Declaring the variable before the loop increases its scope to the calling method (you might want this in some cases, but neither of the cases you described as like that), when the loop ends, the variable remains in scope until the calling method fishes.
Declaring the variable before the loop is also less readable, it also makes the code harder (or at least uglier) to refactor if, for example, you want to take the loop out into its own method.
Finally, and this is my opinion, I don't think you should worry too much about efficiency unless your method is used a lot. The things you need to do to make code efficient quite often makes it less readable (and harder to maintain). There was some quote like "prior optimisation is the thief of good code". Most code doesn't put that much stress on a server (unless you are looping/using it constantly, or the application has an inherently heavy workload, e.g.batch processing), and you should only really optimise code in such circumstances (and then really really optimise the most often executed code. That said, you also need to make sure your code doesn't become bloated, so it's always a bit of a balancing act.
Hope this answers your question.
[Edit]
I'm waiting to be flamed now....
ragnaroknrol The Internet is For Porn[^]
Pete o'Hanlon: If it wasn't insulting tools, I'd say you were dumber than a bag of spanners.
|
|
|
|