|
What have you tried?
Where are you stuck?
This is not a good question - we cannot work out from that little what you are trying to do.
Remember that we can't see your screen, access your HDD, or read your mind.
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
|
|
|
|
|
Im not very good at LINQ (yet), but I understand that I by using the LINQ extension methods in the Enumerable class can do like this to get the largest value in the sequence:
List<int> lst = new List<int>() { 1,2,3,4,5,6,7,8 };
int max = lst.Max();
But what if my List looks like this?
public class MyClass
{
public int Id { get; set; }
public MyClass(int _id)
{ Id = _id; }
}
List<MyClass> lst = new List<MyClass>() { new MyClass(1), new MyClass(2), new MyClass(3) };
I want to get the Id value from the instance with the highest Id value. Im under the impression that I should write a MyClass method and pass it to the Max(...) extension method, but I cant seem to figure out how it would be done. Anyone?
modified 19-Jan-15 5:16am.
|
|
|
|
|
I solved it by myself, turned out it wasnt so complicated.
int m = lst.Max(mc => mc.Id);
|
|
|
|
|
If you only want the value of the maximum ID, you can use either:
int maxId = lst.Select(x => x.Id).Max();
or:
int maxId = lst.Max(x => x.Id);
If you want to get the instance of MyClass which has the maximum ID, you'll need to implement the IComparable<T> interface[^]:
public class MyClass : IComparable<MyClass>
{
public int Id { get; set; }
public MyClass(int _id)
{
Id = _id;
}
public int CompareTo(MyClass other)
{
if (other == null) return 1;
return Id.CompareTo(other.Id);
}
}
...
MyClass maxId = lst.Max();
Unfortunately, there isn't an overload which takes an IComparer<T> instance[^], so if you need different sort orders in different situations, you're stuck with writing your own Max method.
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
Hey there.
I am thinking of writing a little real time game using ASP.NET SignalR.
Unfortunately I have no experience with it whatsoever.
Obviously there will be a database in the background. Let's say we have a table in the background which holds a list of events with userid/creationdate/title. How would I let my user know in real time? As in, event gets added -> immediately send data to user?
I don't need code or anything, I just want to grasp the concept.
|
|
|
|
|
Angelika S Michel wrote: I don't need code or anything, I just want to grasp the concept. Documentation here[^].
Angelika S Michel wrote: I let my user know in real time? According to the website, you can "push" the client a message. That can be done without having a database.
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
That didn't answer my question in any way.. I know that I can push messages. The question is how do I push a message right when a new entry in the database appears.
|
|
|
|
|
The documentation does not say anything about detecting changes in a database; you'll have to do that yourself. You can send or broadcast messages if you detect a change. Examples are here[^], but the ShootR-example shows lots more detail.
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
private void comboBox2_SelectedIndexChanged(object sender, EventArgs e)
{
if (ddl_CircularType != 'Send to Individual')
{
ddl_Department.Enabled = true;
}
else if (ddl_CircularType !='Send to Particular Department')
{
ddl_Department.Enabled = true;
ddl_EmployeeID.Enabled=true;
ddl_EmployeeName.Enabled=true;
}
else if (ddl_CircularType = 'Send to All Employee')
{
ddl_Department.Enabled = true;
ddl_EmployeeID.Enabled=true;
ddl_EmployeeName.Enabled=true;
}
}
|
|
|
|
|
You have asked this also here[^]. Please do not repost.
|
|
|
|
|
sorry for that i am new on this website
ando i dont get answer then i post again
|
|
|
|
|
You have to have patience. Also it's important that the question is clear and well explained. This helps people to understand your problem and give good answers. I see OG has already given you a suggestion so I hope that helps
|
|
|
|
|
|
hari om singh wrote: i dont get answer then i post again
No, don't. It won't help you, it will just annoy people: we don't like duplicated work. And annoying people you want help from is normally counterproductive.
Bear in mind it is a weekend, so most of the Western world is not at work today - this understandably slows responses...
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
|
|
|
|
|
i say sorry for that i dont remembre wekend
|
|
|
|
|
OriginalGriff wrote: Bear in mind it is a weekend, so most of the Western world is not at work today
This kind of activity doesn't count?
|
|
|
|
|
Well, Nagy is in bed hungover, DD is scheming to get his hands on the planning applications committee, and everybody else is being forced to do what their Significant Other has planned for the day...
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
|
|
|
|
|
Sounds like a weekend
|
|
|
|
|
After beat a button in webbrowser's page,a confirm window popup,I can't see it's infomation in ie's source code.How can I get this window's infomation?Thank you.
|
|
|
|
|
What does this have to do with C#?
The difficult we do right away...
...the impossible takes slightly longer.
|
|
|
|
|
oh,let me explain,I want to use Webpage automation operation to deal with my page,so I select c# to do this job with the webbrowser control.
|
|
|
|
|
|
Hi,
I have executed Exchange 2007 commands inside of c sharp code before, but have not attempted to do so with 2013 until now. There are no management tools installed on the machines this app will run on, so I believe I have to open up a remote PSsession to an Exchange 2013 server which is something else I have not done.
I was wondering if any one had an example of doing this with an Exchange 2013 specific cmdlet?
Thank you
|
|
|
|
|
I found this
$session = new-pssession -configurationname microsoft.exchange -connectionuri http://exchangeserver.domain.com/powershell -auth kerberos -credential (get-credential)
import-psession $session
And I can at least see the commands in the powershell session now, so this is a start
|
|
|
|
|
This is telling me the "State of runspace is not valid for this operation" at line 1082, which is the var results2 = powerShell.Invoke(); line.
Any ideas?
using (PowerShell powerShell = PowerShell.Create())
{
powerShell.Runspace = runspace;
string un = @"domain\username";
System.Security.SecureString pw = new System.Security.SecureString();
string password = "password";
foreach (char ch in password)
{
pw.AppendChar(ch);
}
PSCredential cred = new PSCredential(un, pw);
string CONNECTION_URI = @"http://exchangeserver.com/powershell";
PSCommand psSession = new PSCommand();
psSession.AddCommand("$session = New-PSSession");
psSession.AddParameter("ConfigurationName", "Microsoft.Exchange");
psSession.AddParameter("ConnectionUri", new Uri(CONNECTION_URI));
psSession.AddParameter("Kerberos");
psSession.AddParameter("Credential", cred);
psSession.AddParameter("AllowRedirection");
psSession.AddCommand("Import-PSSession");
psSession.AddParameter("$session");
psSession.AddCommand("Get-MailboxDatabaseCopyStatus");
psSession.AddParameter("databasename");
powerShell.Commands = psSession;
var results2 = powerShell.Invoke();
foreach (var item in results2)
{
MessageBox.Show(item.Members.ToString());
}
}
|
|
|
|