There are multiple ways to write code - novice, intermediate, and ninja-level. Let's see some examples below and see how good coding practices can improve code performance as well. Based on the examples below, I urge each developer to review their codes at least once or twice to improve it.
Let us say we have a method.
- private List<Data> getdata()
- {
- return new List<Data>(); // Let us suppose this method returns 10000 rows of Data Object
- }
- for( i=0; i < getdata (); i++) { // }
After a review, it was changed to below,
- var data=GetData();
- for( i=0; i < data ; i++) { // }
Let us take another good example, it involves if-else statements.
See code below,
- if (IsolatedStorageWrapper.LoadString(“ShowTipsAndTricks”) == “”)
- {
- IsolatedStorageWrapper.SaveString(“ShowTipsAndTricks”, “true”);
- }
- else
- {
- IsolatedStorageWrapper.SaveString(“ShowTipsAndTricks”, “”);
- }
- IsolatedStorageWrapper.SaveString(“ShowTipsAndTricks”, IsolatedStorageWrapper.LoadString(“ShowTipsAndTricks”) == “” ? “true” : “”);
After another review,
- var loadedStringValue=IsolatedStorageWrapper.LoadString(“ShowTipsAndTricks”) == “” ? “true” : “”;
- IsolatedStorageWrapper.SaveString(“ShowTipsAndTricks”, loadedStringValue);
After another review,
- var loadedStringValue = IsolatedStorageWrapper.LoadString( “ShowTipsAndTricks” ) == “” ? “true” : “”;
- IsolatedStorageWrapper.SaveString( “ShowTipsAndTricks” , loadedStringValue );

Abubakr MahdiPosted Aug 8, 2019, 11:52 PM
Good Job...
Bidyasagar MishraPosted Aug 7, 2019, 7:30 AM
Really awesome article
Amit MohantyPosted Aug 7, 2019, 6:34 AM
Nicely explained. But I think we can't use foreach loop like this in c# : foreach( i=0; i < data ; i++) { // }