Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
A. Go through the below the code snippets and check whether the coding standards are
followed or not. If not rewrite the codes based on coding conventions and coding standards
and give the reason for correcting the specific code.
1. Code Snippet
Reason:
Corrected Code:
2. Code Snippet:
Corrected Code:
3. Code snippet:
Reason:
Corrected Code:
4. Code snippet:
if (role == "Customer")
{
bCustomer = true;
}
else if (role == "Branch")
{
bIsBranch = true;
}
Reason:
Corrected Code:
5. Code Snippet :
UserGroup usrGrp;
Assignment empAssignment;
Reason:
Corrected Code:
6. Code Snippet :
string str =
File.ReadAllText(@"C:\development\slnfolder\projfolder\myfile.txt");
Reason:
Corrected Code:
7. Code Snippet :
String firstName;
Int32 lastIndex;
Boolean isSaved;
Reason:
Corrected Code:
8. Code Snippet
// Constructor
public Account()
{
// ...
}
}
Reason:
Corrected Code:
9. Code snippet :
Reason:
Corrected Code:
B. Go through the below code snippets and Apply Best Practices and give reason.
// Job 2.
// Send an email to inform the supervisor that the address is changed.
// ...
}
Reason:
Best Practice:
If ( memberType == eMemberTypes.Registered )
{
// Registered user… do something…
}
else
{
// Guest user... do something…
Reason:
Best Practice:
If ( name == “” )
{
// do something
}
Reason:
Best Practice:
Reason:
Best Practice:
return message;
}
Reason:
Best Practice:
Reason:
Best Practice:
16. Which among the following loop usage is the best practice?
a. // loop 1
for(int i = 0; i < a.length; i++)
{
if (!found(a[i]))
continue;
result = a[i];
break;
}
b. // loop 2
for(int i = 0; i < a.length; i++)
{
if (found(a[i]))
{
result = a[i];
break;
}
}
c. // loop 3
for(int i = 0; !resultFound && i < a.length; i++)
{
if (found(a[i]))
{
result = a[i];
resultFound = true;
}
}
a. Convert.ToString(variable) handles NULL values even if variable value become null but
“variable.ToString()” will not handle NULL values it will throw a NULL reference
exception error.
b. “variable.ToString()”handles NULL values even if variable value become null but
Convert.ToString(variable)” will not handle NULL values it will throw a NULL reference
exception error
c. As a good coding practice using “variable.ToString()”is always safe.
d. All the above
18. Which among the following is true about The int.TryParse method?
b. Strings are immutable, so each time a string is changed, a new instance in memory is
created.
c. StringBuilder is mutable; when you modify an instance of the StringBuilder class, you
modify the actual string, not a copy
20. Which are the standard prefixes for the Button and RadioButtonList controls respectively?
Feedback:
Incorrect
Answers:
Date:
Score: