Skip to content
InfinityKnow

InfinityKnow

Infinity Knowledge (IK) : Technology, Articles, Topics, Facts or many More.

  • Home
  • Education
    • yttags
    • Make Money
    • Jobs
    • Programming
      • Technology
      • Web Design
      • WEB HOSTING
      • Interview
  • Entertainment
    • pakainfo
    • Sports
    • Tips and Tricks
      • Law
      • Photography
      • Travel
  • Health
    • Insurance
    • Lifestyle
      • Clothing
      • Fashion
      • Food
  • News
    • Insurance
      • Auto Car Insurance
      • Business Insurance
    • Donate
    • California
  • News
    • Political
  • Home Improvement
  • Trading
    • Marketing
    • Top Tranding
    • Business
    • Real Estate
  • Full Form
  • Contact Us
  • C# Dictionary Tutorial with Examples Technology
  • SharePoint Migration Services
    Why SharePoint Migration Services is Important for Businesses ? Articles
  • Dynamically Set navbar active tab angularjs ngclass
    Dynamically Set navbar active tab angularjs ngclass Technology
  • Christmas quotes Quotes
  • sez full form – sez Kya Hai, Meaning and Abbreviation – What is the full form of sez? full form
  • Angular json array object string parse Technology
  • Funny shayari in hindi Shayari
  • Remove All White spaces using jQuery Example
    Remove All White spaces using jQuery Example Technology

C# Code Optimizing Tutorial with Examples

Posted on July 26, 2018 By admin No Comments on C# Code Optimizing Tutorial with Examples

C# Code Optimizing Tutorial with Examples

Today, We want to share with you C# Code Optimizing Tutorial with Examples.
In this post we will show you Optimizing C# Code, hear for Code Optimization Techniques we will give you demo and example for implement.In this post, we will learn about Tips to Improve Performance of C# Code with an example.

Optimizing C# code

In this post,I will list some of useful technique for Optimizing C# code.

Now in this post, I will explain about Optimizing C# Application.  Optimization is the process of modifying a code to enhance its performance or efficiency. Code optimization is a truly required an aspect of writing an efficient C#.Net based application. The following tips will help you to enhance the speed and efficiency of your C# code and applications.

1. Replace ArrayList with List<>

ArrayList are benefial when storing multiple types of objects or data within the same list. But if you are storing the same type of variables in one ArrayList, you can gain a more performance by using List<> objects instead.

[php]
ArrayList StudentList = new ArrayList();
StudentList.Add(“jaydeep”);
return (int)StudentList[0] + “Astha”;
[/php]

In the above code it only contains string(Student Name). Using the List<> class is much better. To convert it to a typed List, only the variable types need to be changed.

READ :  VueJS MVC Application Architecture - VueJS model view controller example

[php]
List StudentList = new List();
StudentList.Add(“Astha”);
return StudentList[0] + “jaydeep”;
[/php]

Now,In the above code there is no need to cast types with [php]List<>[/php]. The performance increase can be especially significant with primitive data types like integers,float,decimal etc.

2. Use && and || operators

When using condition statement like if statements, simply make use of the double-and notation [php](&&)[/php] and/or the double-or notation (||), (in Visual Basic they are [php]AndAlso and OrElse)[/php].

Condition statement statements that use & and | must check every condition of the statement and then apply the “and” or “or”. On the other hand, && and [php]||[/php] go thourgh the statements one at a time and stop as soon as the condition has either recognized as true or false.

consider the following C# code:

[php]
if (obj != null && obj.getCount())
[/php]

In the above line of code, If [php]obj[/php] is null, with the [php]&& operator, obj.getCount() [/php]will not execute. If the [php]&&[/php] operator is replaced with [php]&, obj.getCount()[/php] will run even if [php]obj[/php] is already known to be null, and it will result in an exception.

READ :  AngularJS Material Introduction and Hello World example

3. Knowing when to use StringBuilder over String

You may have heard before that a StringBuilder is faster at appending strings together than normal string types.

The fact is StringBuilder is faster mostly with big strings. This means if you have a loop that iterates and add to a single string for many iterations then a StringBuilder class is definitely much faster than a string type.

But if you just want to append some value to a string a single time then a StringBuilder class is overkill. A simple string type variable, in this case, improves on resources use and readability of the C# source code.

4. Comparing Non-Case-Sensitive Strings

Sometimes it is required to compare two string variables,by ignoring the cases. The traditional approach is to convert both strings to all lower case or all upper case and then compare them,

[php]
name1.ToLower() == name2.ToLower()

[/php]

In the above code, calling the function ToLower() is a bottleneck in performace. By instead using the built-in string.Compare() function you can increase the speed of your applications.

You can check if two strings are equal ignoring case would look like below code:

READ :  Angular Call Function on Page Load Example

[php]
string.Compare(name1, name2, true) == 0 //Ignoring cases
[/php]

The C# string.Compare function returns an integer that is equal to 0 when the two strings are equal.

5. Smart Try-Catch

Try-Catch statements are useful to catch an exceptions that are beyond the programmers control, such as connecting to the web or a device for example. Using a try statement to keep code “simple” instead of using if statements to avoid error-prone calls makes code incredibly slower. Restructure your source code to require less try statements.

6. Avoid Divisions

C#.Net is comparatevely slow when it comes to division operations.Another way is to replace divisions with a multiplication-shift operation to further optimize C#.

Read :

  • Technology
  • Google Adsense
  • Articles

Summary

You can also read about AngularJS, ASP.NET, VueJs, PHP.

I hope you get an idea about Optimizing C# Code Tips.
I would like to have feedback on my Infinityknow.com blog.
Your valuable feedback, question, or comments about this article are always welcome.
If you enjoyed and liked this post, don’t forget to share.

Related posts:

  1. Vuejs Simple Navigation Menu vue router-link params
  2. vuejs toggle class – vue js v-class – Dynamic Components in Vuejs
  3. Vuejs Simple Tooltip Plugin v-tooltip Example
  4. Responsive Navigation Menu CSS Free download
Technology, Asp.Net Tags:c# code optimization techniques pdf, c# code optimization tools, c# code optimization tools online, c# loop optimization, c# performance tricks: how to radically speed up your code, code optimization examples in c#, high performance c#, how to improve performance of code in c#

Post navigation

Previous Post: Difference between Stack and Heap memory in C#.NET
Next Post: C# Prime Number Program Tutorial with Examples

Related Posts

  • Difference Between String and Stringbuilder using C# Technology
  • Include common header and footer using Vuejs - router-view
    Include common header and footer using Vuejs – router-view Technology
  • Laravel 6 custom validation Date Format Examples Technology
  • Comprehensive Guide
    A Comprehensive Guide to Choose the Vetiver Fragrances Articles
  • ASP.NET UpdateProgress control Tutorial with Examples Technology
  • Angular ng-focus Directive Set Focus on Textbox Technology

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Categories

  • Account web hosting (1)
  • AngularJs (277)
  • Articles (143)
  • Asp.Net (49)
  • Astrology (2)
  • Attorney (7)
  • Auto Car Insurance (4)
  • Biography (2)
  • Business (9)
  • Business Insurance (3)
  • California (4)
  • Choose the web hosting (1)
  • Clothing (6)
  • cloud (8)
  • Cloud data storage (2)
  • Credit (1)
  • Dedicated hosting server web (1)
  • Dedicated server web hosting (1)
  • Dedicated web hosting (1)
  • Degree (11)
  • Design (9)
  • Differences shared hosting (1)
  • Donate (2)
  • Education (37)
  • Energy web hosting (1)
  • Entertainment (6)
  • Facts (12)
  • Fashion (3)
  • Finance (3)
  • Food (5)
  • full form (90)
  • Google Adsense (22)
  • Health (21)
  • Home Improvement (5)
  • Insurance (7)
  • Interview (2)
  • Jobs (6)
  • jquery (2)
  • jQuery (2)
  • Laravel (164)
  • Lawyer (4)
  • Lifestyle (6)
  • Loans (6)
  • Make Money (31)
  • Managed dedicated server (1)
  • Managed hosting solution (1)
  • Managed servers (1)
  • Marketing (8)
  • Mortgage (2)
  • Movies (21)
  • MySQL (180)
  • News (5)
  • Photography (1)
  • PHP (250)
  • Programming (18)
  • Quotes (75)
  • Real Estate (2)
  • SEO (9)
  • Shared web hosting (1)
  • Shayari (67)
  • Sports (5)
  • Status (34)
  • Stories (45)
  • suvichar (8)
  • Tech (3)
  • Technology (675)
  • Tips and Tricks (43)
  • Top Tranding (36)
  • Trading (28)
  • Travel (12)
  • Uncategorized (8)
  • VueJs (179)
  • Web Design (2)
  • WEB HOSTING (1)
  • Web hosting company (1)
  • Web hosting really (1)
  • Web hosting windows (1)
  • Which website hosting (1)
  • Wishes (13)
  • wordpress (15)

Categories

AngularJs (277) Articles (143) Asp.Net (49) Attorney (7) Business (9) Clothing (6) cloud (8) Degree (11) Design (9) Education (37) Entertainment (6) Facts (12) Food (5) full form (90) Google Adsense (22) Health (21) Home Improvement (5) Insurance (7) Jobs (6) Laravel (164) Lifestyle (6) Loans (6) Make Money (31) Marketing (8) Movies (21) MySQL (180) News (5) PHP (250) Programming (18) Quotes (75) SEO (9) Shayari (67) Sports (5) Status (34) Stories (45) suvichar (8) Technology (675) Tips and Tricks (43) Top Tranding (36) Trading (28) Travel (12) Uncategorized (8) VueJs (179) Wishes (13) wordpress (15)
  • KatmovieHD 2021: Download Latest Bollywood, Hollywood Dubbed Movies & TV Shows For Free Movies
  • Moz Group Buys
    Moz Group Buys – What is It and How Can You Take Benefit From It? Articles
  • Lunch Box
    10 Keys About Lunch Box With Ice Pack Compartment Technology
  • What does an IT Support Specialist do? Tips and Tricks
  • WordPress Remove Yellow BGBOX – donate PHP
  • vuejs-datepicker vuejs datetimepicker – Vuejs Calendar Example
    vuejs-datepicker vuejs datetimepicker – Vuejs Calendar Example Technology
  • Best National Public Colleges & Universities in the United States
    Best National Public Colleges & Universities in the United States Education
  • suv full form – suv Kya Hai, Meaning and Abbreviation – What is the full form of suv? full form

Copyright © 2022 InfinityKnow.

Powered by PressBook News WordPress theme