The availability of features may depend on your plan type. Contact your Customer Success Manager if you have any questions.

Dev guideRecipesAPI Reference
Dev guideAPI ReferenceUser GuideLegal TermsGitHubDev CommunityOptimizely AcademySubmit a ticketLog In
Dev guide

Update from older versions of the C# SDK

Describes how to update from older versions of the Optimizely Full Stack (Legacy) C# SDK to Optimizely Feature Experimentation.

This section provides code examples for how Optimizely recommends leveraging the new Decision and Event Tracking APIs. All existing Full Stack (Legacy) methods and implementation are still supported. See Optimizely Feature Experimentation - application & migration documentation for the latest updates.

Optimizely recommends adopting the new Decide, Decide All, and Track Event methods as a more flexible and easier-to-use replacement where you currently use IsFeatureEnabled, GetFeatureVariable, GetAllFeatures, or Track calls within your implementation.

The following are examples of how to migrate the Full Stack (Legacy) methods to Feature Experimentation methods:

using OptimizelySDK;
using OptimizelySDK.Entity;
using OptimizelySDK.OptimizelyDecisions;

/*
 * Prerequisites for new methods: create a user
 */
var optimizely = OptimizelyFactory.NewDefaultInstance("YOUR_SDK_KEY");
var attributes = new UserAttributes
{
    { "is_logged_in", true }
};
var user = optimizely.CreateUserContext("user_123", attributes);

/*
 * Is Feature Enabled
 */
// old method
bool enabled = optimizely.IsFeatureEnabled("flag_1", "user_123", attributes);

// new method
var decision = user.Decide("flag_1");
bool enabled = decision.Enabled;

/*
 * Activate & Get Variation
 */
// old method
var variation = optimizely.Activate("experiment_1", "user_123", attributes);

// new method
var variationKey = decision.VariationKey;

/*
 * Get All Feature Variables
 */
// old method
var json = optimizely.GetAllFeatureVariables("flag_1", "user_123", attributes);

// new method
var json = decision.Variables;

/*
 * Get Enabled Features
 */
// old method
var enabledFlags = optimizely.GetEnabledFeatures("user_123", attributes);

// new method
var options = new[] { OptimizelyDecideOption.ENABLED_FLAGS_ONLY };
var decisions = user.DecideAll(options);
var enabledFlags = decisions.Keys;

/*
 * Track
 */
// old method
var tags = new EventTags
{
    { "revenue", 42 }
};
attributes.Add("purchase_count", 2);
optimizely.Track("my_purchase_event_key", "user_123", attributes, tags);

// new method
user.TrackEvent("my_purchase_event_key", tags);