Sei sulla pagina 1di 10

Training Effectiveness Assessment

Employee Id: Date:

Employee Name: Technology: Coding Standards and Best


Practices.
Project: Level:

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

public class clientactivity


{
public void clearstatistics()
{
//...
}
public void calculatestatistics()
{
//...
}
}

Reason:

Corrected Code:

2. Code Snippet:

public class UserLog


{
public void Add(LogEvent LogEvent)
{
int ItemCount = LogEvent.Items.Count;
// ...
}
}
Reason:

Corrected Code:

3. Code snippet:

© Changepond Technologies Confidential Page 1


Training Effectiveness Assessment
int iCounter;
string strName;

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;

© Changepond Technologies Confidential Page 2


Training Effectiveness Assessment

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

public class Account


{

public string Number {get; set;}


public DateTime DateOpened {get; set;}

© Changepond Technologies Confidential Page 3


Training Effectiveness Assessment
public DateTime DateClosed {get; set;}
public decimal Balance {get; set;}
public static string BankName;
public static decimal Reserves;

// Constructor
public Account()
{
// ...
}
}

Reason:

Corrected Code:

9. Code snippet :

//Populate empId from database which is not a not null column.

int employeeId= reader["employeeid"];

Reason:

Corrected Code:

B. Go through the below code snippets and Apply Best Practices and give reason.

10. Code snippet :

// Save address and send an email to the supervisor to inform that


// the address is updated.
SaveAddress ( address, email );

© Changepond Technologies Confidential Page 4


Training Effectiveness Assessment
void SaveAddress ( string address, string email )
{
// Job 1.
// Save the address.
// ...

// Job 2.
// Send an email to inform the supervisor that the address is changed.
// ...
}

Reason:

Best Practice:

11. Code Snippet :

If ( memberType == eMemberTypes.Registered )
{
// Registered user… do something…
}
else
{
// Guest user... do something…

// we introduce another user type in future


}

© Changepond Technologies Confidential Page 5


Training Effectiveness Assessment

Reason:

Best Practice:

12. Code Snippet :

If ( name == “” )
{
// do something
}

Reason:

Best Practice:

13. Code Snippet:

void SendMail (string message, string mailType)


{
switch ( mailType )
{
case "Html":
// Do something
break;
case "PlainText":
// Do something
break;
case "Attachment":
// Do something
break;
default:
// Do something
break;

© Changepond Technologies Confidential Page 6


Training Effectiveness Assessment
}
}

Reason:

Best Practice:

14. Code Snippet :

public string ComposeMessage (string[] lines)


{
string message = String.Empty;

for (int i = 0; i < lines.Length; i++)


{
message += lines [i];
}

return message;
}

Reason:

Best Practice:

© Changepond Technologies Confidential Page 7


Training Effectiveness Assessment

15. Code Snippet:


void ReadFromFile ( string fileName )
{
try
{
// read from file.
}
catch (Exception ex)
{
return "";
}
}

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;
}
}

© Changepond Technologies Confidential Page 8


Training Effectiveness Assessment

17. What is the difference between .tostring() and Convert.tostring()?

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?

a. It converts string into int


b. It never throws an exception—even on invalid input and null.
c. The method returns true if it succeeds, and false if it doesn't.
d. All the above

19. Which of the following is incorrect about System.Text.StringBuilder and System.String?

a. StringBuilder is more efficient when there is a large amount of string manipulation.

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

d. Strings are mutable in .Net

20. Which are the standard prefixes for the Button and RadioButtonList controls respectively?

a. btn and rblst


b. btn and rbl
c. cmd and rblst
d. cmd and rbl

Feedback:

© Changepond Technologies Confidential Page 9


Training Effectiveness Assessment

Correct Answers: Evaluated By:

Incorrect
Answers:

Date:
Score:

© Changepond Technologies Confidential Page 10

Potrebbero piacerti anche