Changes to C# and .NET Framework

Eric points out some of the new syntax changes we’ve made in C# 2.0 for FCLC compliance.  These changes could break some of your existing code so you should make sure to verify 1.1 code when moving to VS 2005 (Whidbey).


You should also be aware of the new BCL changes that will help developers write decent and non-offensive code, including changes to System.String and a new exception class. 



To check whether a string contains indecent content, developers can now call the IsIndecent method which returns true or false if the string is indecent.  Below is the copy/paste from ObjectBrowser on one of our latest VS builds (40326) 

public static bool IsIndecent(string str)

    Member of System.String



Determines whether a specified System.String object is indecent. 



str: A System.String.


Return Values:                                       

 true if the value of str is indecent, otherwise, false.  



if (String.IsIndecent(text))


//Do something here             



We have also added the ability to estimate the cost of an FCLC fine based on the contents of a string using a new method, EstimateFine.

public static float EstimateFine(string str)

    Member of System.String



Provides an estimate of an indecency fine based on string contents using floating-point precision. 



str: A System.String.


Return Values:                                       

Single-precision floating point estimate of FCLC fines. 



float f = String.EstimateFine(text);


Note – We’ve also added a culture specific overload to EstimateFine which enables you to estimate indecency fines in other cultures.  Currently this returns 0.0 except when the culture is set to ‘EN-US’.

public static float EstimateFine(string str, System.Globalization.CultureInfo culture)


We’ve also changed the behavior of strings so that a string marked with a public accessor (ex: public string s;) that contains indecent content will now raise a System.IndecentException as outlined below:



public class IndecentException : System.Exception

    Member of System



The exception that is thrown when the content of a string with a public access modifier is indecent. 



Other keywords

We are still debating this, so any feedback is appreciated.  Are any of the following language constructs, classes, properties, or methods listed below considered offensive or indecent?

  • unsafe
  • using
  • sizeof
  • EntryPointNotFoundException
  • MakeDirty() (System.Windows.Forms.AxHost)
  • SetDirtyObject (System.Web.UI.StateManagedCollection)
  • IsDirty() (System.Runtime.InteropServices)

Your feedback, as always, is appreciated.

Comments (14)

  1. Brad Williams says:

    Wouldn’t EstimateFine for EN-US just be:

    float EstimateFine(string str)


    if (IsIndecent(str))

    return 500000.0;


    return 0.0;


    Guess it can’t be hard coded though (unless there’s a constitutional amendment), so this better activate a web service instead, maybe can host?

  2. KCJacob says:

    Nice one Dan! You almost had me there. Then I remembered the date.

  3. joe says:

    Why is this a part of the string class? Isn’t the string class heavy enough as it is? What’s the point of namespaces if they aren’t going to be used properly?

    It should be something like…

    Microsoft.Utils.ContentFilter.IsDecent or something like that.

    /me groans

  4. AndrewSeven says:

    Well from what I see, a TrimIndecent or equivalent method is absolutely required.

    I would also recommed naming the exception IndecencyException; it is a good exception and should not have negative name.

    I hope that there are compile time checks so we don’t have to wait until runtime IndecencyExceptions are thrown for readonly and const strings.

    It is important not to overlook enums, as they are often exposed to end users.

    Also numbers, what about 666?

  5. Wallym says:

    Which namespace are these changes going into?






  6. cmalpeli says:

    nice one Dan! LOL!

  7. Majik says:

    If you’re going to have an IsDirty() method, you need to also use the System.Jackson.Michael namespace.

    Also, it’s Bubba has two b’s… not sure how that compiled. 😛

  8. Luke says:

    public boolean IsIndecent()


    return IndexOf("java") != -1;


  9. Leeor says:

    rofl! Great one! 🙂

  10. icelava says:

    using System.Fool;

  11. David Weller says:

    I noticed that Eric took down his post 🙂

  12. Microsoft Developer Dan Fernandez reports on the future of the C# language: System.String To check whether a string contains indecent content, developers can now call the IsIndecent method which returns true or false if the string is indecent. Source: iBLOGthere4iM…

  13. Robert says:

    Incredible idea an integrated text filtering utility is long overdue. I don’t think it belongs in the string class. Also there should be a way to abstract and updatethe data.

    Especially because it should have room to grow and become more robust – like localization, exclude ContainsEmailAddress(), ContainsUrl(), HasSpellErrors(), SpellErrorCount, SpellErrorPercentage, ContainsSpamWords(), ContainsSpamIPs,

    For example, I have been working on a home grown multi-lingual utility like this. I have been bitching all the way through that something like this is not already out there and set as a platform to customize and improve by a whole community.

    For example a poster to a French forum who says he posted in French say 1000 characters. If average word size in French is 5 that is 200 words. A simple realtime filter can be to run a string against a spell-checker’s vocabulary and return 140 spelling mistakes or 70% of all words have a typo.

    if(SpellErrorPercent>50){ String.IsWrongLanguage;

    Response.Write("Ce n’est pas français")