Tag Archive: translation


What is the equivalent to regsvr32 in .NET?

Where you once used Regsvr32 on unmanaged COM libraries, you will now use Regasm on managed .NET libraries.

Regsvr32 is

Does C# support variable arguments (vararg’s) on methods?

There was a suggestion/question on the Product Feedback site for VS2005 that suggested that the params keyword may not be that well understood.

The params keyword can be applied on a method parameter that is an array.

How to keep a local variable in scope across a try and catch block?

The following code won’t work, because conn goes out of scope before you enter the catch block.

[code:c#]

Q: Why does C#’s iterators feature spit out a class definition instead of a struct definition?

Why does my switch statement works differently?

C# does not support an explicit fall through for case blocks (unless the block is empty)

For an explanation of why, see Why is the C# switch statement designed to not allow fall through, but still require a break? on MSDN

The following code is not legal and will not compile in C#:

[code:c#]
switch (x){

Are Generics in .NET like Templates in C++?

No.

While Generic types do have a similar syntax to C++ templates, they are instantiated at runtime as opposed to compile time, and they can be reflected on via meta-data.

This post applies to Visual

The code is trying to access a member of a reference type variable that is set to null.

Given the following class, let’s examine some code that could be in the Main method:

[code:c#]
using System;

class Foo
{

Why must attribute properties be read/write in C#?

Q: Why must attribute properties be read/write in C#?

In the C# language, when you define an attribute class, you can define both constructor arguments and properties. For example:

[code:c#]
class MyAttribute: Attribute
{

Why doesn’t C# support static method variables?

Q: In C++, it’s possible to write a static method variable, and have a variable that can only be accessed from inside the method. C# doesn’t provide this feature. Why?

A: There are two reasons C# doesn’t have this feature.

First, it is possible to get nearly the same effect by having a class-level static, and adding method statics would require increased complexity.

Second, method level statics are somewhat notorious for causing problems when code is called repeatedly or from multiple threads, and since the definitions are in the methods, it’s harder to find the definitions.

Powered by WordPress | Theme: Motion by 85ideas.