We all might have encountered in which sometimes we need to ignore the returned values, especially the "out" arguments, and the best example is the TryParse method in which we check whether the string can be parsed to another type.
In the aboe code I want to ignore "boolParsedValue" and also want to make this variable inaccessible for developers so that they can reference it. With new C# 7.0, you can achieve this goal using "discards"
Discards are write-only local variable, in which you can assign but cannot read. They don't have names but are represented by "_ (underscore)". Since _ cannot be read, it will not appear on the right side of an assignment. Discard in the above code will be as below.
Because _ is not readable, it will not appear in IntelliSense nor will compile the code.
Now suppose in the above code you explicitly define the _ variable and assign the value true, in that case _ will be not considered as discard since you are explicitly declaring the _ local variable.
Value of v in the above code false, if you see properly in the check condition we have written out var _, and it will overrides the scope of previously declared _ variable. Assignment v = _ just reads the previously declared local variable (false) and assigns to v.
Recently I had a requirement in which I need to call a .NET library class method from SQL Server Stored Procedure and Microsoft SQL Server does provide that feature. Basically It was kind of string manipulation and we also used for calculating the numbers for which the algorithm was defined in .Net function. For example in our case we need to get the amount with GST included.
Creating the Class Library
First step is create the .Net class library and we have to make sure the target framework supports the Microsoft SQL Server feature of calling the CLR methods. I have created a class library targeting .net framework 4.5 and will be using the class library in SQL Server 2014.
First thing, we need to ensure that the method we need to call from SQL Server is marked as static and also we need to decorate the function with Microsoft.SqlServer.Server.SqlProcedure attribute. Below is my code which I am using.
Register the Class Library in SQL Server
Once the class library is finalized and ready to execute from SQL Server, you need to execute some basic SQL script before utilizing it.
Register Class Library in SQL Server
Once the script has finished executing, you will find the registered assembly under the Database\Programmability\Assemblies node in SQL Server Management Studio. If you look under “Database\Programmability\Functions”, you'll find the method you registered earlier. You can now call your method as a standard T-SQL function call.