Regex for numbers only

Use the beginning and end anchors. Use “^\d+$” if you need to match more than one digit. Note that “\d” will match [0-9] and other digit characters like the Eastern Arabic numerals ٠١٢٣٤٥٦٧٨٩. Use “^[0-9]+$” to restrict matches to just the Arabic numerals 0 – 9. If you need to include any numeric representations other than just digits (like decimal values for starters), then … Read more

C# cannot convert method to non delegate type

You need to add parentheses after a method call, else the compiler will think you’re talking about the method itself (a delegate type), whereas you’re actually talking about the return value of that method. Extra Non-Essential Information Also, have a look at properties. That way you could use title as if it were a variable, … Read more

Where can I find the assembly System.Web.Extensions dll?

EDIT: The info below is only applicable to VS2008 and the 3.5 framework. VS2010 has a new registry location. Further details can be found on MSDN: How to Add or Remove References in Visual Studio. ORIGINAL It should be listed in the .NET tab of the Add Reference dialog. Assemblies that appear there have paths in … Read more

Categories c# Tags

How can I get the application’s path in a .NET console application?

System.Reflection.Assembly.GetExecutingAssembly().Location1 Combine that with System.IO.Path.GetDirectoryName if all you want is the directory. 1As per Mr.Mindor’s comment:System.Reflection.Assembly.GetExecutingAssembly().Location returns where the executing assembly is currently located, which may or may not be where the assembly is located when not executing. In the case of shadow copying assemblies, you will get a path in a temp directory. System.Reflection.Assembly.GetExecutingAssembly().CodeBase will return the ‘permanent’ path … Read more

The remote server returned an error: (403) Forbidden

Add the following line: This will let the application use the credentials of the logged in user to access the site. If it’s returning 403, clearly it’s expecting authentication. It’s also possible that you (now?) have an authenticating proxy in between you and the remote site. In which case, try: Hope this helps.

Categories c# Tags

Adding values to a C# array

You can do this way – Alternatively, you can use Lists – the advantage with lists being, you don’t need to know the array size when instantiating the list. Edit: a) for loops on List<T> are a bit more than 2 times cheaper than foreach loops on List<T>, b) Looping on array is around 2 times cheaper than looping on … Read more

How to fix “namespace x already contains a definition for x” error? Happened after converting to VS2010

I had this happen to me about a year ago and I don’t remember exactly what the root cause was, but there are two things you might try: If it’s an auto-generated file (as ‘Resources.Designer.cs’ tend to be), try deleting it and letting VS re-generate it. Either separately or in conjunction with #1, select Show All … Read more

how to convert C# to C++

Actually as it is complicated to mix C# and C++ on unix, I am trying to convert C# to C++ Have you considered Mono? It is something that’s definitely worth checking before starting to learn C++ in order convert and run an existing .NET application on Unix. It’s also binary compatible meaning that you don’t even … Read more