Blog - Title

  • The C# Team

    How can I easily log a message to a file for debugging purposes?

    • 12 Comments
    Often, you need a way to monitor your applications once they are running on the server or even at the customer site -- away from your Visual Studio debugger. In those situations, it is often helpful to have a simple routine that you can use to log messages...
  • The C# Team

    Parallel Programming: Task Schedulers and Synchronization Context

    • 23 Comments
    Thanks to everyone who provided feedback on my previous post Parallel Programming in .NET Framework 4: Getting Started . As promised, I am continuing the series. This time, let’s go a little bit deeper and talk about task schedulers , synchronization...
  • The C# Team

    Why doesn't C# have a power operator?

    • 29 Comments
    Some languages provide a power operator, so one can write something like: float result = value^2; rather than having to resort to calling. We don't have one in C#. It would be possible to add a power operator to the language, but performing this...
  • The C# Team

    How do I write a method that accepts a variable number of parameters?

    • 11 Comments
    Update: Named and optional (default) parameters are available starting from C# 4.0. For more information, see Named and Optional Arguments (C# Programming Guide) . Q: How do I write a method that accepts a variable number of parameters? ...
  • The C# Team

    Why doesn't C# support static method variables?

    • 24 Comments
    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...
  • The C# Team

    Understanding a Simple Async Program

    • 5 Comments
    by Alan Berman The Async feature in Visual Studio 2012 RC makes it easy to invoke asynchronous methods. If you mark a method with or async modifier, you can use the await operator in the method. When control reaches an await expression in the async...
  • The C# Team

    Dynamic in C# 4.0: Creating Wrappers with DynamicObject

    • 17 Comments
    In the previous post I showed how you can use the new dynamic feature and the ExpandoObject class to add and remove properties at run time, and how this can make your code more readable and flexible than code written with LINQ to XML syntax. But there...
  • The C# Team

    How do I get and set Environment variables?

    • 6 Comments
    Use the System.Environment class. Specifically the GetEnvironmentVariable and SetEnvironmentVariable methods. Admitedly, this is not a question specific to C#, but it is one I have seen enough C# programmers ask, and the ability to set environment variables...
  • The C# Team

    How do C# generics compare to C++ templates?

    • 28 Comments
    Q: How do C# generics compare to C++ templates? A: This is really a fairly complex topic. Anders has touched on it in an interview . I should state at the outset that the goals of generics are not the same as the goals of templates. There are...
  • The C# Team

    Why doesn't C# support #define macros?

    • 37 Comments
    In C++, I can define a macro such as: #define PRODUCT(x, y, z) x * y * z and then use it in code: int a = PRODUCT(3, 2, 1); C# doesn't allow you to do this. Why? There are a few reasons why. The first is one of readability. One of our...
  • The C# Team

    Why doesn't C# have VB.NET's 'with' operator?

    • 41 Comments
    Many people, including the C# language designers, believe that 'with' often harms readability, and is more of a curse than a blessing. It is clearer to declare a local variable with a meaningful name, and use that variable to perform multiple operations...
  • The C# Team

    What's the difference between override and new?

    • 19 Comments
    This is all to do with polymorphism. When a virtual method is called on a reference, the actual type of the object that the reference refers to is used to decide which method implementation to use. When a method of a base class is overridden in a...
  • The C# Team

    How do I send out simple debug messages to help with my debugging?

    • 5 Comments
    Visual Studio offers tons of useful debugging features and allows you to step through your code line-by-line. However, there are times when you don’t want to step through your application, but want to make it output simple text strings with variable values...
  • The C# Team

    How to use LINQ methods to compare objects of custom types

    • 11 Comments
    LINQ provides a convenient syntax and many useful methods for operating with collections of objects. However, to be correctly processed by LINQ comparison methods such as Distinct or Intersect , a type must satisfy certain requirements. Let’s take...
  • The C# Team

    What’s Next in C#? Get Ready for Async!

    • 19 Comments
    Today we announced the Visual Studio Async CTP , which shows one of the major features we plan to include in a future release of C# and Visual Basic. This feature makes development of asynchronous applications--which include everything from desktop applications...
  • The C# Team

    Converting a VBA Macro to C# 4.0

    • 26 Comments
    I've talked a lot about improved COM interop in C# 4.0 and how much easier it is now to work with Office applications. This time I want to share some tips and tricks on how you can convert Visual Basic for Applications (VBA) macros to C# 4.0 by using...
  • The C# Team

    C# 4.0 PowerPoint Presentations

    • 47 Comments
    Alexandru Ghiondea from the C# team created an excellent deck of slides that he used at Microsoft Days 2010 in Bulgaria. The C# team reused the deck several times for User Groups' presentations and talks. If you are planning a talk at your User Group...
  • The C# Team

    Crystal Reports for Visual Studio 2010

    • 29 Comments
    Crystal Reports has been a part of Visual Basic since 1993, and a part of Visual Studio since its first release in 2002. Crystal Reports has been a very successful component of these products. With the release of Visual Studio 2010, SAP and Microsoft...
  • The C# Team

    How do I play default Windows sounds?

    • 6 Comments
    Sometimes, you might want to make your application a bit more audible. If you are using .NET 2.0, you can utilize the new System.Media namespace and its SystemSound and SystemSounds classes. The SystemSounds class contains five static properties that...
  • The C# Team

    What's the difference between string and System.String?

    • 12 Comments
    C# defines a number of aliases for CLR types. They may be used interchangably, and even mixed together, e.g. string x = new System.String(' ', 5); . These are the aliases defined: Alias CLR type string System.String ...
  • The C# Team

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

    • 19 Comments
    The following code won't work, because conn goes out of scope before you enter the catch block. try { Connection conn = new Connection(); conn.Open(); } catch { if (conn != null ) conn.Close(); } The fix is simple - just declare conn before entering the...
  • The C# Team

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

    • 4 Comments
    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. When the method is invoked, the...
  • The C# Team

    Ask a FAQ Question

    • 208 Comments
    Do you have a FAQ about: The C# Language or compiler The C# IDE The Visual Studio debugger Reply to this post, and your question will be added to our list to be answered. Of course, depending on the nature of your comment, and the volume...
  • The C# Team

    Taking a tour of Roslyn

    • 21 Comments
    It’s a big day for us on the Managed Languages team! As announced at the //BUILD conference earlier today, and as posted by Soma on his blog , we are not just delivering a new preview of Roslyn to all of you, but are in fact moving all of the compiler...
  • The C# Team

    How can I get objects and property values from expression trees?

    • 8 Comments
    This is a follow-up to the Getting Information About Objects, Types, and Members with Expression Trees post, so I would recommend that you read that one first. Among other code examples in that blog post, I demonstrated how you can get a property name...
Page 2 of 6 (142 items) 12345»