473,327 Members | 1,892 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,327 software developers and data experts.

C#-APP: Simple efficiency related questions in C#

Hi all!

I'm new to .NET Platform and got some simple questions about efficiency...

To put you in situation, to say that I'm involved in the writing of a complex regex based lexer for use over the .NET RichTextBox component. Since the lexing is done in realtime at the time the user is typing/editing on the RichTextBox, it is high time consuming, so I'm trying to do the best to get the most efficient code. So here we go:

1. Suppose I declared a simple type variable, int x for example. At some point in the code the value of x is unknown, and I need it to take a specific value. Is more efficient to assign it directly or to check if it has the value I want, and if false, then assign it?

//At this point the value for 'x' is unknown. I need it to take value 0.
OptionA:
x = 0;
OptionB:
if (x != 0) { x = 0; }
2. I have some methods involved in the lexing of text that are called hundred of times. I have some simple type local variables declared inside these methods to control the processing itself. Since simple types in C# are objects, will be more efficient to declare these variables outside the methods as instance variables to avoid the overload of creating and destructing these objects each time the methods are called? Do really worth in terms of efficiency making visible these variables to the rest of the class (which is not a good thing in terms of coding style)?

Thanks in advance!
Nov 28 '07 #1
1 1156
kenobewan
4,871 Expert 4TB
I'm not sure what course you are doing, but I hope it is free because it appears to worth be nothing. You are learning that's fine but come back when you have a project you are working on and you have problems - you have gotten your hands dirty. I am closing this thread.

MODERATOR
Nov 30 '07 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

30
by: Dimitris | last post by:
Hi folks... As part of an assignment, I have to design and implement a fairly small MYSQL 4.0.17 database for a fictitious travel agency. This database will store data from customers submitting...
5
by: Haines Brown | last post by:
Re. <title>, my impression has been that a line break is _NOT_ allowed in the contained text. Is that true? Also, I gather a double quotation mark in the text string (and ampersand, etc.) _IS_...
16
by: Harlan Messinger | last post by:
1. CSS has five generic font family specifiers: serif, sans-serif, cursive, fantasy, monospace. IE lets the users select a default proportional font and a default monospace font. Is there any way...
3
by: Jan Waga | last post by:
Hello, I've written and installed windows service in C#. I have two questions: 1) File.Open("lock", FileMode.OpenOrCreate, FileAccess.Read, FileShare.None) does not create the file even if...
5
by: Ivan Demkovitch | last post by:
Hi! I'm building my portal and I found that some times I need to dinamically generate address. Since I have many modules and each could have it's own parameters in order to preserve other's...
3
by: James Simpson | last post by:
Hello, I am currently deploying an ASP .NET based web application via Visual Studio 2005 (so I am using .NET 2.0 technology). The two questions I have are with regards to session state in...
2
by: Mani kansal | last post by:
hi, as m recently get into this field.hav done first module yet and doin 2nd 1.can someone pls guide me as from where i could get the sql related problems so that i can apply my concepts on...
13
by: John Dann | last post by:
A Python newbie, but some basic understanding of how classes, objects etc work in eg VB.Net. However, I'm struggling a little to translate this knowledge into the Python context. I'm trying to...
8
AmberJain
by: AmberJain | last post by:
Hello, My new semester has started and I have a subject named DBMS (Database Management System). This is the first time I'm studying databases and so I'm not feeling very enthusiastic about...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.