What needs to be done for a class to be used inside a using block

To enable a class to be used under a using() block, the class must implement the IDisposable interface with its own implementation of the Dispose() method.

public class MyClass : IDisposable {
    public void Dispose() {
      // implementation of Dispose method
    }
}

// in some other method
using(var myclass = new MyClass()) {
    // myclass instance is alive inside 
    // this block only
}

Dispose is never called by the .NET Framework; you must call it manually - preferably by wrapping its creation in a using() block.

How do you handle errors Globally in ASP.NET Core?

We can make use of the built-in UseExceptionHandler() middleware for catching Global Errors in ASP.NET Core.

app.UseExceptionHandler(err =>
   {
        err.Run(async ctx =>
        {
            context.Response.StatusCode = 500;
            context.Response.ContentType = "application/json";
            // gets error detail
            var ex =  context.Features.Get<IExceptionHandlerPathFeature>();
            var error = new MyResponseModel() { Content = ex.Error.Message };
            await context.Response.WriteAsync(JsonConvert.SerializeObject(error));
        });
    });

How do you throw custom errors in SQL

We can use raiseError to throw custom exceptions in an P-SQL block.

Example:

RAISERROR (N'Error Raised: %s %d.', -- Message text.  
           10, -- Severity,  
           1, -- State,  
           N'number', -- First argument from the 
           5); -- Second argument.  

Returns Error Message: Error Raised: number 5.

Compute and generate a compressed string for a given string containing repetitions

For a given string return a compressed string which replaces all the repetitions of the characters with their counts. If the compressed string is not smaller than the initial string return the original string as it is. For example, if the input string is "aabbbbbcccdddeef", then the resultant string should be "a2b5c3d3e2f1", whereas if the input string is "abcdef" then the output should be "abcdef".