RegEx best practices in C# [closed] - c#

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 7 years ago.
Improve this question
I came across writing Regular Expressions against user input in a C# console application, here are a couple of questions:
When a RegEx becomes pretty long like below, is it smart to keep where it is in the code? Or put it with my other constants in their own class? Or even smarter to just not use it and do it some other way?
Regex regEx = new Regex(#"\w+([-+.]\w+)*#\w+([-.]\w+)*\.\w+([-.]\w+)*([,;]\s*\w+([-+.]\w+)*#\w+([-.]\w+)*\.\w+([-.]\w+)*)*");
How does RegEx affect the behavior/load of my application and what more do I have to consider when using RegEx?

You should definitely use Regular Expressions. You should however look out for the performance implications if used incorrectly. If you are using it frequently, you should look at using Compiled Regular Expressions.
For further reading on the performance & best practices there is a nice MSDN article http://blogs.msdn.com/b/bclteam/archive/2010/06/25/optimizing-regular-expression-performance-part-i-working-with-the-regex-class-and-regex-objects.aspx

Related

How to compare string with for loop in c# [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 4 years ago.
Improve this question
I'm creating a mini code generator in c#. Say i have a string
string val= "i=0;i<5;i++";
As I'm taking complete structure of for loop as a string. How to find the syntax error if user gives wrong input? For example terminator missing or other logical errors? Should i have to use regex?
No i don't think regex is good option because you have to take many things into consideration.
but i would suggest try this instead
https://support.microsoft.com/en-us/help/304655/how-to-programmatically-compile-code-using-c-compiler
using c# compiler itself to do work for you.
but keep that in mind this will ask for whole c# code so you may have to do some string manipulation to get around that.

good practises null object return [closed]

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 7 years ago.
Improve this question
I have a question about c# programming language, when a method returns an object, and for example I'm forced to return null, which is not clean code, what is the best practise to handle this? I dont want to return null.
EDIT
This was a question because it started as discussion on a software engineering class after reading Clean Code - Robert C. Martin 's book and it really came to my mind that trying to avoid this added unnecesary complexity to the design.
In case to signal "failed to create object" C++ class constructs throws exceptions for this purpose.
Some languages / projects prefer to use exceptions more to keep happy-pass happier while others may not.

What is the best use of a variable when required by multiple methods [closed]

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 8 years ago.
Improve this question
I'm using XmlManager to
do xml manipulations in several methods in a class.where I should declare XmlManager variable ?
1.locally within each method and do intialization.
2 declare at globally and initiate at the method level
As it is, in this question, there's absolutely NO difference whatsoever because there's neither performance gain nor significant design issues.
Maybe if the question is put into context there could be reason to choose one approach over the other, but as it stands now. None of the approach is better than the other one

Is "massive" usage of #region considered a bad practice? [closed]

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 9 years ago.
Improve this question
My MainViewModel has to deal with a lot of commands with complex actions inside, therefore its extension has grown inevitable. For keep the code organized I tend to use #region to group similar o related tasks.Does this considered an overuse of this feature or it's perfectly normal? You may say that it depends on me, if I feel right about it. I think that it helps a lot but I would like to know what do others. Here is a screenshot of how the code look like:
The bad practice is a massive single class. #region is simply hiding / coping with it.
If there are groups of methods, delegate them to another class.

anyone have any comment on Business Logic Toolkit for .NET? [closed]

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 9 years ago.
Improve this question
hi
i am taking a look now # Business Logic Toolkit for .NET http://bltoolkit.net .
but the strange thing is that i dont see anyone using it but from the documentation it seems very nice.
so my question is why there is no one using this library?
i want to use it but i am afraid there is somethings wrong that dont let the people use it.
thanks
Hi i think the problem is that bltoolkit more popular in russia development comunity. Other problems are: no dependecy injection, no full linq support.

Categories

Resources