Tech
Forums
Jobs
Books
Events
Videos
Conference
Annual Conference
Bcrypt
Ai Conference
Live
More
Interviews
Certification
Training
Career
Members
News
Blogs
Contribute
An Article
A Blog
A Video
An Ebook
An Interview Question
Register
Login
2
Answers
the role of void and return keyword
Ask a question
Ask a question
Upload Source Code:
Select only zip and rar file.
Johnny Nguyen
13y
2k
1
Reply
Hi Guys!
When try to answer the questions to prepare for text, I got the question like this: Consider the C# method below. What happens if the keyword
return
is removed?
public void FireCannonBall()
{
foreach ( GameObject ball on cannonBalls)
{
if (!ball.alive)
{
ball.alive= true;
ball.position= cannon.position-ball.center;
ball.velocity= new Vector2((float)Math.Cos(cannon.rotation),(float)Math.sin(cannon.rotation))* 5.0f;
return;
}
}
}
I my opinion,if the keyword return is removed, we will meet the error.This class is void class, so it is cannot return. we remove the keyword return,the compiler will not understand and do not return ball.velocity to float type.
Is that the right answer????
Could you please help me to find the correct answer for the question?
Regards
Jonny
Post
Reset
Cancel
Answers (
2
)
Next Recommended Forum
Raising event in another form
the Array