RSS Feed for TechnicalCategory: Technical

Is there a way to force garbage collection? »

Yes. Set all references to null and then call System.GC.Collect(). If you need to have some objects destructed, and System.GC.Collect() doesn’t seem to be doing it for you, you can force finalizers to be run by setting all the references to the object to null and then calling System.GC.RunFinalizers().

Is there an equivalent of exit() for quitting a C# .NET application? »

Yes, you can use System.Environment.Exit(int exitCode) to exit the application or Application.Exit() if it’s a Windows Forms app.

Is there any sample C# code for simple threading? »

Yes:
using System;
using System.Threading;
class ThreadTest
{
public void runme()
{
Console.WriteLine(\”Runme Called\”);
}
public static void Main(String[] args)
{
ThreadTest b = new ThreadTest();
Thread t = new Thread(new ThreadStart(b.runme));
t.Start();
}
}

Is there regular expression (regex) support available to C# developers? »

Yes. The .NET class libraries provide support for regular expressions. Look at the System.Text.RegularExpressions namespace.

My switch statement works differently than in C++! Why? »

C# does not support an explicit fall through for case blocks. The following code is not legal and will not compile in C#:
switch(x)
{
case 0: // do something
case 1: // do something as continuation of case 0
default: // do something in common with
//0, 1 and everything else
break;
}
To achieve the same effect in C#, the code [...]

What is the difference between a struct and a class in C#? »

From language spec: The list of similarities between classes and structs is as follows. Longstructs can implement interfaces and can have the same kinds of members as classes. Structs differ from classes in several important ways; however, structs are value types rather than reference types, and inheritance is not supported for [...]

What is the equivalent to regsvr32 and regsvr32 /u a file in .NET development? »

Try using RegAsm.exe. Search MSDN on Assembly Registration Tool.

What is the syntax for calling an overloaded constructor within a constructor (this() and constructorname() does not compile)? »

The syntax for calling another constructor is as follows: class B { B(int i) { } } class C : B { C() : base(5) // call base constructor B(5) { } C(int i) : this() // call C() { } public static void Main() {} }