Ask a FAQ Question

Ask a FAQ Question

Rate This

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 we receive, we may not get to every question.

Note that if your question is not about C# specifically (if it is, for example, a Windows Forms question or a general question about the .NET Framework), it would be better to post that question to a newsgroup or web forum. Visit http://msdn.microsoft.com/vcsharp/community/ for a listing of related resources.

Thanks!

Leave a Comment
  • Please add 3 and 6 and type the answer here:
  • Post
  • The CLR seems to support co-variant return types. Will co-variant return types be supported in the next version of C#?
  • Why doesn't C# support changing the return type of overriding methods to derived types, e.g.

    class c1
    {
    public virtual c1 Negate() {..;}
    }
    class c2: c1
    {
    public override c2 Negate() {..;}
    }
    class c3: c2
    {
    public override c3 Negate() {..;}
    }

    Up to now I have to use workarounds like the following to support such behaviour (get's even more overhead in my case):

    class c1
    {
    public c1 Negate() {return InnerNegate();}
    protected c1 InnerNegate() {..;}
    }
    class c2: c1
    {
    public new c2 Negate() {..;}
    protected override c1 InnerNegate() {return Negate();)
    }
    class c3: c2
    {
    public new c3 Negate() {..;}
    protected override c1 InnerNegate() {return Negate();)
    }
  • ************************************
    If I have this...

    string s = "this is a test";

    why couldn't I do this in C#'s immediate window?

    ?s.IndexOf("this")

    I will get "error: 's.IndexOf' does not exist" message. It works in VB.NET.

    I have to wirte my own a generic method if I want to evaluate an expression that contains an object's function.
    ************************************

    You get the annoying same behavior with .ToString() or .ToUpper() in the immediate window.

  • Why does not VS support ^shtml^ files - does not color the code there like in html files. In order to get it work I have to patch the registry.
  • There should be such a function :

    String.isnullorempty() =

    (String.isnull() || String.isempty())

    I do this a lot.

  • Why does c# requires 2bytes for storing array of booleans. However it takes 1 byte as a single site.

  • I actually posted about this on my blog at http://schweitn.blogspot.com/2004_02_01_schweitn_archive.html#107782132911035587

    The basic question is why doesn't C# support something similar to const reference parameters in C++? The problem lies in that there is no way for me as the caller of a method to know whether my argument to that method which is a reference type won't be changed. I think this is a huge shortcoming in C#/.NET ... and really kills programming safety, especially if someone is using a third party assembly where I can't look at the code and see what's happening. I want the compiler/CLR watching my back.
  • Does C# have support for FTP connections like C++ does in the CFtpConnection and CInternetSession classes?

  • Why does the IDE start to lock files after 15/20 projects in the one solution? How do we avoid this, and how do we fix this?

    Why does the IDE basically start to break down after 30 projects? Locking files, losing intellisense, problems attaching to IIS (6) while debugging an asp.net app (need to reboot in order to fix this).

    A fix would be to build some of the projects and make static references to their dll's. In many cases this is not realistic because to manage this would take up most of a developers day.

    ps. I was recently talking with Habib Heydarian [habibh@microsoft.com] but he simply stopped returning emails and left my issues unanswered.

  • Why doesn't C# implements the "throws" clause as Java ?
    How can I be sure that I capture all the possible exceptions throw by a class,or just when I have to capture one ??

    Thanks.
  • Q1. Why doesn't C# support conditional tests as part of SEH, such as try..filter..catch in CIL or Try..Catch..When in VB?

    Q2. Why doesn't C# provide a more flexible means of specifying interface implementation? E.g.

    protected virtual void MyMethodCore() implements IMyInterface.MyMethodCore {...}

    instead of

    void IMyInterface.MyMethod() { MyMethodCore(); }

    protected virtual void MyMethodCore() {...}
  • Okay check this out...

    My DBA writes procs that take integers..if I have class member variable defined as an integer I can't assign an integer a null value obviously (ya ya value type, stored on the stack, I know I know)

    But sometimes I have to pass SQL Server a null value, my variable is an int, the proc expects an int, but in SQL Server as you all know if you have a proc that takes an int you can just say

    exec usp_SomeProc @MyInt = NULL and Sql server will completely treat the Int like a null..and ignore that parameter

    thats all well and good...however you know the poor middle tier guy designing the classes can't pass an integer parameter with the value null...

    i.e int x = null;//error , yeah we know

    I know whats coming, use SqlTypes right...

    But consider this situation where a class has a field called ID that is SqlInt32, but you get into a situation where you need to assign this field from a value in ViewState

    so

    SomeClass sc = new SomeClass();
    sc.ID = (SqlInt32)ViewState["VendorID"];//Error!

    Yessir...System.Data.SqlTypes.SqlInt32 is not serializable..so you will get the error:The type 'System.Data.SqlTypes.SqlInt32' must be marked as Serializable or have a TypeConverter other than ReferenceConverter to be put in viewstate.

    Thats not cool..whats up with that...maybe the C# team isn't responsible, but could you ask the guys who are this question..why make it implement INullable and not ISerializable? It causes me much grief and I have to resort to cheap tricks..
  • Q: Why doesn't C# have a "handles" keyword?

    In VB.Net, it's easy to hook up events using the "Handles" keyword. E.g.:

    Private Sub TextBox_TextChanged(sender As Object, e As EventArgs) Handles currencyTextBox.TextChanged

    In C#, the same is rather cumbersome -- using += and -= to manually subscribe/unsubscribe to the handlers.

    I understand that the VB Handles keyword is really just syntactic sugar, but IMO it makes for more maintainable and readable code. += and -= seem like overkill for handling simple events.

    Did the C# team consider adding a "handles" type keyword, and, if so, what was the justification for leaving it out? Are there plans to add a "handles" keyword in Whidbey or later versions of C#?
  • Interesting new blog at blogs.msdn.com - "C# Frequently Asked Questions", where the C# team posts answers to common C# questions. Subscribed. Why doesn't C# support default parameters? Why doesn't C# support multiple inheritance? Why doesn't C# support #define macros? Ask your question here....
  • Why C# support variable values for attributes (like [Foo(x)]) however; vb.net does not allow that?
Page 2 of 13 (194 items) 12345»