Just few days back , I ran into a code block syntax ,which looked quite a bit different to me in terms of a regular code I see .. Well this was been used in the Designer for HTML
<%= ModificationType.GetHashCode().ToString() == "1" ? "Pre" : "Post" %> which dint really make any sense to me whatsoever .. Upon asking one of the Developer out here ,he asked me to google Shorthand in C# . So following his advice I went on my best tool (Google).. and did some research to find out it is very similar to If Than Else statement in Programming .. Infact one can say its the same thing but writing it differently..
As far as Development is concerned I have realised that for one piece of a problem , there can be multiple ways to solve them .. Choosing the bestest one which suits our requirenment ,among several best ones is a challenge and that comes with experience and ones understanding .
Going back to the code
<%= ModificationType.GetHashCode().ToString() == "1" ? "Pre" : "Post" %> indicates that if the object ModificationType is equal to 1 than the data is related to Pre ,else it is related to Post ..
Giving another example let us consider this an if else statement like
if (test > 8)
{
test = 12;
}
else
{
test = 5;
}
so instead of using this long code , why dont we use a shortcut like
test=test>8 ? 12:5;
No comments:
Post a Comment