c# - Devrait 39; utiliser les directives #39 à l'intérieur ou à l'extérieur de l'espace de nom

Mots clés : c#.netnamespacesstylecopcode-organizationc#

meilleur 4 Réponses c# - Devrait 39; utiliser les directives #39 à l'intérieur ou à l'extérieur de l'espace de nom

vote vote

98

// File1.cs using System; namespace Outer.Inner {     class Foo     {         static void Bar()         {             double d = Math.PI;         }     } } 
// File2.cs namespace Outer {     class Math     {     } } 
// File1b.cs namespace Outer.Inner {     using System;     class Foo     {         static void Bar()         {             double d = Math.PI;         }     } } 
vote vote

83

namespace MyCorp.TheProduct.SomeModule.Utilities {     ... } 
namespace MyCorp {     namespace TheProduct     {         namespace SomeModule         {             namespace Utilities             {                 ...             }         }     } } 
using System; using System.Collections.Generic; using System.Linq; //using MyCorp.TheProduct;  <-- uncommenting this would change nothing using MyCorp.TheProduct.OtherModule; using MyCorp.TheProduct.OtherModule.Integration; using ThirdParty;  namespace MyCorp.TheProduct.SomeModule.Utilities {     class C     {         Ambiguous a;     } } 
namespace MyCorp.TheProduct.SomeModule.Utilities {     using System;     using System.Collections.Generic;     using System.Linq;     using MyCorp.TheProduct;                           // MyCorp can be left out; this using is NOT redundant     using MyCorp.TheProduct.OtherModule;               // MyCorp.TheProduct can be left out     using MyCorp.TheProduct.OtherModule.Integration;   // MyCorp.TheProduct can be left out     using ThirdParty;      class C     {         Ambiguous a;     } } 
vote vote

72

using ThisNamespace.IsImported.InAllNamespaces.Here;  namespace Namespace1 {     using ThisNamespace.IsImported.InNamespace1.AndNamespace2;     namespace Namespace2    {        using ThisNamespace.IsImported.InJustNamespace2;    }        }  namespace Namespace3 {     using ThisNamespace.IsImported.InJustNamespace3; } 
vote vote

68

using System; using Guid = System.Guid;  namespace Microsoft.Sample {     public class Program     {     } } 
namespace Microsoft.Sample {     using System;     using Guid = System.Guid;      public class Program     {     } } 
namespace Microsoft.Sample {     using Guid = System.Guid;     public class Guid     {         public Guid(string s)         {         }     }      public class Program     {         public static void Main(string[] args)         {             Guid g = new Guid("hello");         }     } } 

Questions similaires