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
harish reddy
NA
162
33.9k
Methods in C Sharp
Feb 9 2018 8:40 AM
Sir,
I am starting methods in c sharp and i have confustion with pass by value and reference.
also i get confused what passes incase of arrays.
example in the below code of Write a method that checks whether an element, from a certain position in an array is greater than its two neighbours.
static
void
Main()
{
int
[] array=
new
[] {1,2,3,2,5,8,7,9};
int
position =
int
.Parse(Console.ReadLine());
ElementCheck(position, array);
}
static
void
ElementCheck(
int
newposition,
int
[] array)
{
if
((array[newposition]> array[newposition-1]) && (array[newposition]> array[newposition+1]))
{
Console.WriteLine(
"Greater"
);
}
else
{
Console.WriteLine(
"Not greater"
);
}
}
Questions are :
1. I am calling ElementCheck(position, array); but how will all the elements of array pass to the elementcheck?
Also, can we return string ...for exampe like this below:
static
void
Main()
{
int
[] array=
new
[] {1,2,3,2,5,8,7,9};
int
position =
int
.Parse(Console.ReadLine());
ElementCheck(position, array);
}
static
string
ElementCheck(
int
newposition,
int
[] array)
{
if
((array[newposition]> array[newposition-1]) && (array[newposition]> array[newposition+1]))
{
return
greater?;
}
else
{
return
notgreater?;
}
}
This code gives me error. Why?
Reply
Answers (
2
)
return value in post method using async Task(C# And Mongodb)
Regarding data managment