TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Mart Nta
NA
9
942
how can i change console code to win Forms
Jul 24 2019 3:42 PM
public
static
decimal
GetMedian(
this
IEnumerable <
int
> source) {
// Create a copy of the input, and sort the copy
int
[] temp = source.ToArray();
Array.Sort(temp);
int
count = temp.Length;
if
(count == 0) {
throw
new
InvalidOperationException(
"Empty collection"
);
}
else
if
(count % 2 == 0) {
// count is even, average two middle elements
int
a = temp[count / 2 - 1];
int
b = temp[count / 2];
return
(a + b) / 2 m;
}
else
{
// count is odd, return the middle element
return
temp[count / 2];
}
}
public
static
int
GetMode(
this
IEnumerable <
int
> list) {
// Initialize the return value
int
mode =
default
(
int
);
// Test for a null reference and an empty list
if
(list !=
null
&& list.Count() > 0) {
// Store the number of occurences for each element
Dictionary <
int
,
int
> counts =
new
Dictionary <
int
,
int
> ();
// Add one to the count for the occurence of a character
foreach
(
int
element
in
list) {
if
(counts.ContainsKey(element))
counts[element]++;
else
counts.Add(element, 1);
}
// Loop through the counts of each element and find the
// element that occurred most often
int
max = 0;
foreach
(KeyValuePair <
int
,
int
> count
in
counts) {
if
(count.Value > max) {
// Update the mode
mode = count.Key;
max = count.Value;
}
}
}
return
mode;
Reply
Answers (
3
)
Asp net web api token authentication
class parameters by Ref