What is good coding practices in c#? [Resolved]

Posted by Programmer123 under C# on 11/21/2013 | Points: 10 | Views : 1393 | Status : [Member] | Replies : 7
What is good coding practices in c#. I mean to say while doign the coding, what type precautions we need to take so that the code will be more optimized and run fast.




Responses

Posted by: Bandi on: 11/21/2013 [Member] [MVP] Platinum | Points: 50

Up
0
Down

Resolved
http://stackoverflow.com/questions/2063652/net-best-coding-practice-to-achieve-compiler-best-performance
http://www.vcskicks.com/optimize_csharp_code.php
http://dotnet.sys-con.com/node/46342

Mark This Response as Answer
--
Chandu
http://www.dotnetfunda.com/images/dnfmvp.gif

Programmer123, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Allemahesh on: 11/22/2013 [Member] [MVP] Silver | Points: 50

Up
0
Down

Resolved
Below are some tips:-

1. User Connection Pooling
2. Implement a "Using" block to manage resources properly.
3. Never implement try-Catch within loop.
4. Choose best collection according to your purpose. Below are the list of fast first and so on...
-> List<int> or List<string>
-> int[] arr
-> Dictionary<int, int>
5. StringBuilder consumes less memory than String.
6. Use of String.Empty to check whether the string is null or not
7. Change your style of type casting. Below are the list of fast first and so on..
-> Base c = d as Base;
-> Base b = (Base) d;
8. Efficient string comparison method. Below are the list of fast first and so on..
-> if (Value.Equals("Sourav"))
-> if (Value == "Sourav")

Happy Coding,
If it helps you or directs U towards the solution, MARK IT AS ANSWER

Programmer123, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Allemahesh on: 11/22/2013 [Member] [MVP] Silver | Points: 50

Up
0
Down

Resolved
Also see the below links:-

http://www.c-sharpcorner.com/UploadFile/dacca2/5-tips-to-improve-performance-of-C-Sharp-code/
http://www.c-sharpcorner.com/UploadFile/dacca2/5-tips-to-improve-performance-of-C-Sharp-code-part-4/
http://www.tuicool.com/articles/iuiu6nv

Happy Coding,
If it helps you or directs U towards the solution, MARK IT AS ANSWER

Programmer123, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Allemahesh on: 11/22/2013 [Member] [MVP] Silver | Points: 50

Up
0
Down

Resolved
Below is the good link for C# Optimizations:-

http://www.dotnetperls.com/optimization


Happy Coding,
If it helps you or directs U towards the solution, MARK IT AS ANSWER

Programmer123, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Programmer123 on: 11/21/2013 [Member] Starter | Points: 25

Up
0
Down
Bandi, In the link:- http://www.vcskicks.com/optimize_csharp_code.php, they are saying use string-builder instead of string.
Can you tell me what is the max size of string so that I can use string builder instead of string.

Programmer123, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Bandi on: 11/21/2013 [Member] [MVP] Platinum | Points: 25

Up
0
Down
Hi,
Strings cannot have more than 2^31 ( 2 power 31 = 2,147,483,647) characters, since String.Length is a 32-bit integer.
They're also limited by available memory.

The theoretical limit of a string length may be 2,147,483,647, but the practical limit is nowhere near that. Since no single object in a .Net program may be over 2GB and the string type uses unicode (2 bytes for each character), the best you could do is 1,073,741,823, but you're not likely to ever be able to allocate that on a 32-bit machine.

Mark This Response as Answer
--
Chandu
http://www.dotnetfunda.com/images/dnfmvp.gif

Programmer123, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response