C# 7.0 now allows using underscore _ to be used a digit separator.
This adds more readability.
Similarly, we now have Binary Literals, so instead of specifying hexadecimal pattern we can specify bit patterns.
Hope it helps..
C# 7.0 now allows using underscore _ to be used a digit separator.
This adds more readability.
Similarly, we now have Binary Literals, so instead of specifying hexadecimal pattern we can specify bit patterns.
Hope it helps..
Out Parameters must need to declared before they are used in the method which doesn’t seem intuitive.
Now with C# 7.0 we can now make use of Out variable.
Here in our second call to the method we have used out variable named outVariableString which we didn’t have to declare like output parameter.
Hope it helps..
Tuple are used when we need to get more than one value returned from the method.
C# 7.0 introduces Tuple Types and Tuple Literals to Tuples
We need to add System.ValueType Nuget Package to add the required assemblies to Visual Studio.
Below sample code shows usage of Tuple type and literal. In our second method, we have named the part of the tuple i.e. name and number.
Now to access the first method we use Item1 and Item2 field, however for our second method as we have named the part we can use those names to access them i.e. name and number.
Output in both the case
Hope it helps..
C# 7.0 adds a new feature called local functions.
Local functions allow us to define function within a function. It can be used to write helper methods that we need to use inside that function’s scope.
Here in the below sample code we have defined one main function (MainFunction) that has one local function(MultiplyBy10LocalFunction) defined inside it. And that local function has one more local function(Add10LocalFunction) defined inside it.
Hope it helps..
Here we will be creating a storage account of type blob storage and a container inside it. Then we will create a console application, add required nuget packages and upload a file to the container.
Log in to Azure Portal
Click on Add to add a new storage account.
Create a new container in it to store the blob files
Now we’d write a console app to connect to this container and upload a file.
Create a new console application and add references to below Nuget Packages.
In Azure Portal – Storage Account, go to Access Keys and copy the connection strings for the storage account.
Inside console application add an appSettings section and add a key and paste the above copied connection string there.
The source code to upload the Blob file
// Retrieve storage account from connection string. CloudStorageAccount storageAccount = CloudStorageAccount.Parse( CloudConfigurationManager.GetSetting("StorageConnectionString")); // Create the blob client. CloudBlobClient blobClient = storageAccount.CreateCloudBlobClient(); // Retrieve a reference to a container. CloudBlobContainer container = blobClient.GetContainerReference("myblogcontainer"); // Retrieve reference to a blob named "myblob". CloudBlockBlob blockBlob = container.GetBlockBlobReference("WeekendChamps.jpg"); // Create or overwrite the "myblob" blob with contents from a local file. using (var fileStream = System.IO.File.OpenRead(@"C:\Users\Bliss\Downloads\WeekendChamps.jpg")) { blockBlob.UploadFromStream(fileStream); }
The file uploaded in the container
Hope it helps..
EPPlus is .NET Library that makes it very easy to manipulate Excel programmatically. It is based on Open XML.
Below is the sample code we can use to insert a chart in a excel spreadsheet.
</p> <p>public void UpdateExcelUsingEPPlus(string fileName)<br /> {<br /> FileInfo fileInfo = new FileInfo(fileName);</p> <p>ExcelPackage p = new ExcelPackage(fileInfo);</p> <p>// access the first sheet named Sheet1<br /> ExcelWorksheet myWorksheet = p.Workbook.Worksheets["Sheet1"];</p> <p>// specify cell values to be used for generating chart.<br /> myWorksheet.Cells["C2"].Value = 10;<br /> myWorksheet.Cells["C3"].Value = 40;<br /> myWorksheet.Cells["C4"].Value = 30;</p> <p>myWorksheet.Cells["B2"].Value = "Yes";<br /> myWorksheet.Cells["B3"].Value = "No";<br /> myWorksheet.Cells["B4"].Value = "NA";</p> <p>// add chart of type Pie.<br /> var myChart = myWorksheet.Drawings.AddChart("chart", eChartType.Pie);</p> <p>// Define series for the chart<br /> var series = myChart.Series.Add("C2: C4", "B2: B4");<br /> myChart.Border.Fill.Color = System.Drawing.Color.Green;<br /> myChart.Title.Text = "My Chart";<br /> myChart.SetSize(400, 400);</p> <p>// Add to 6th row and to the 6th column<br /> myChart.SetPosition(6, 0, 6, 0);</p> <p>p.Save();</p> <p>}</p> <p>
The output –
If we want to do it using Open XML SDK without using EPPlus Library we can refer to the below article.
https://msdn.microsoft.com/en-us/library/office/cc820055.aspx
Hope it helps..