Why is the @ sign used in things like page redirects?

Can someone explain why people use the @ sign in things like page redirections?

For example;

response.redirect(@”mypage.aspx”);

Seems to work exactly the same as;

response.redirect(“mypage.aspx”);

I would like to know the purpose of the @ sign.

Answers:

Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.

Method 1

The @ before the string indicates the string is a verbatim string:
So if you are redirecting to a page that is not on the current location as the view, you could say response.redirect(@"pathmypage.aspx"). Without the @, you have to say response.redirect("path\mypage.aspx")

For your code, you do not need it since the page you are redirecting to is on the same location.

Reference:
https://docs.microsoft.com/en-us/dotnet/csharp/language-reference/tokens/verbatim


All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x