.NET Standard vs Portable Class Library (PCL)

πŸ’‘ Concept Name

.NET Standard vs PCL (Portable Class Library)

πŸ“˜ Quick Intro

Both PCL and .NET Standard were designed to enable code sharing across .NET platforms. However, .NET Standard simplifies this process and has effectively replaced PCLs.

🧠 Analogy / Short Story

Imagine PCL as packing a suitcase for a trip with *specific airlines*β€”you can only take what's allowed by all of them. .NET Standard, on the other hand, gives you a universal luggage listβ€”pack once, use it on all airlines. Much simpler!

πŸ”§ Technical Explanation

  • πŸ“¦ **PCL** targets *intersections* of APIs supported by selected platforms.
  • 🧩 **.NET Standard** defines a *common set* of APIs all platforms must implement.
  • πŸ”§ PCL was complex to maintain due to various profile combinations.
  • πŸš€ .NET Standard is easier to version, and supports broader platform compatibility.
  • ❌ PCL has been deprecated in favor of .NET Standard and .NET 5+.

🎯 Purpose & Use Case

  • βœ… Use .NET Standard to create reusable libraries across .NET Framework, .NET Core, Xamarin, and more.
  • βœ… Helps unify code for cross-platform apps.
  • ❌ Avoid PCLs in new projects β€” limited support and tooling.

πŸ’» Real Code Example

A .NET Standard class library can be referenced by multiple app types:

// MyLibrary.csproj
<Project Sdk="Microsoft.NET.Sdk">
  <PropertyGroup>
    <TargetFramework>netstandard2.0</TargetFramework>
  </PropertyGroup>
</Project>

public class MathUtils {
    public static int Square(int x) => x * x;
}

❓ Interview Q&A

Q1: What is the main purpose of .NET Standard?
A: To provide a uniform set of APIs for all .NET implementations.

Q2: What does a PCL target?
A: The common subset of APIs supported by selected .NET platforms.

Q3: Is PCL still recommended?
A: No, it’s deprecated.

Q4: Can .NET Standard be used with Xamarin?
A: Yes, fully supported.

Q5: What is a major downside of PCLs?
A: Complexity due to intersection-based profiles and limited API availability.

πŸ“ MCQs

Q1. .NET Standard is preferred over PCL because:

  • It’s older
  • It uses more memory
  • It provides a uniform API surface for all platforms
  • It’s only for Xamarin

Q2. What does a PCL define?

  • All APIs in .NET
  • Common APIs supported by selected platforms
  • Xamarin-specific APIs
  • None of these

Q3. Which one is deprecated?

  • .NET Standard
  • PCL
  • Both
  • Neither

Q4. Is .NET Standard compatible with .NET Core?

  • No
  • Yes
  • Only with converters
  • Only in preview builds

Q5. What’s a key benefit of .NET Standard?

  • Platform-specific APIs
  • Low memory
  • Cross-platform compatibility
  • Better threading

πŸ’‘ Bonus Insight

With the evolution of .NET 5 and later, you don’t need to choose between .NET Standard and .NET Core β€” everything is unified under a single platform. Use .NET Standard only if you need compatibility with older runtimes.

πŸ“„ PDF Download

Need a handy summary for your notes? Download this topic as a PDF!

➑️ Next:

πŸ’¬ Feedback
πŸš€ Start Learning
Share:

Tags: