Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // code cleanup, yay
- // original code
- private string UserAgent
- {
- get
- {
- if (Context.Headers != null) {
- return Context.Headers["User-Agent"];
- }
- return null;
- }
- }
- // braces, private keyword unnecesarry
- string UserAgent
- {
- get
- {
- if (Context.Headers != null)
- return Context.Headers["User-Agent"];
- return null;
- }
- }
- // use ternary
- string UserAgent
- {
- get
- {
- return Context.Headers != null
- ? return Context.Headers["User-Agent"]
- : null;
- }
- }
- // further optimizations are C# 7 specific
- // fancy get-only property thing
- string UserAgent => Context.Headers != null
- ? return Context.Headers["User-Agent"]
- : null;
- // fancy null-check thing
- private string UserAgent => Context.Headers?.Get("User-Agent");
- // note: I only used the .Get() form of this because I can't use square brackets after the ?. operator
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement