Write a c program to find out sum of digit of given number

Code 1: C program to add digits of a number C program for sum of digits of a number C program to calculate sum of digits #include<stdio.h> int main(){ int num,sum=0,r; printf(“Enter a number: “); scanf(“%d”,&num); while(num){ r=num%10; num=num/10; sum=sum+r; } printf(“Sum of digits of number:  %d”,sum); return 0; } Sample output: Enter a number: 123 Sum of digits of number:  6 Code 2: Sum of digits of a number in c using for loop #include<stdio.h> int main(){ int num,sum=0,r; printf(“Enter a number: “); scanf(“%d”,&num); for(;num!=0;num=num/10){ r=num%10; sum=sum+r; } printf(“Sum of digits of number:  %d”,sum); return 0; } Sample output: Enter a number: 567 Sum of … Continue reading Write a c program to find out sum of digit of given number

WCF Application Demo To save and retreive the data from a table

1. Create a WCF application and named as SampleWcfService 2. Add this code in IService1.cs using System; using System.Collections.Generic; using System.Linq; using System.Runtime.Serialization; using System.ServiceModel; using System.ServiceModel.Web; using System.Text; namespace SampleWcfService { // NOTE: You can use the “Rename” command on the “Refactor” menu to change the interface name “IService1” in both code and config file together. [ServiceContract] public interface IService1 { [OperationContract] string GetData(int value); [OperationContract] CompositeType GetDataUsingDataContract(CompositeType composite); [OperationContract] Employee GetEmployee(int Id); [OperationContract] void SaveEmployee(Employee Employee); // TODO: Add your service operations here } // Use a data contract as illustrated in the sample below to add composite … Continue reading WCF Application Demo To save and retreive the data from a table

Linq Distinct By

What you need is a “distinct-by” effectively. I don’t believe it’s part of LINQ as it stands, although it’s fairly easy to write: public static IEnumerable DistinctBy (this IEnumerable source, Func keySelector) { HashSet seenKeys = new HashSet(); foreach (TSource element in source) { if (seenKeys.Add(keySelector(element))) { yield return element; } } } So to find the distinct values using just the Id property, you could use: var query = people.DistinctBy(p => p.Id); And to use multiple properties, you can use anonymous types, which implement equality appropriately: var query = people.DistinctBy(p => new { p.Id, p.Name }); Untested, but it … Continue reading Linq Distinct By

Make CSV from list of string in LINQ

There are not any one liners to do this with LINQ. Note that you can use the Aggregate method to do this, but you will be using string concatenation instead of a StringBuilder. I would consider adding an extension method for this if it something you will be doing often: public static string ToCsv(this IEnumerable source) { if (source == null) throw new ArgumentNullException(“source”); return string.Join(“,”, source.Select(s => s.ToString()).ToArray()); } Continue reading Make CSV from list of string in LINQ

How Grouping working in Linq

Copy paste the code as it is in a blank page with ConsoleApplication1 using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ConsoleApplication1 { class Program { static void Main(string[] args) { var employeeGroup = from employee in Employee.GetAllEmployees() group employee by employee.Department; foreach (var group in employeeGroup) { Console.WriteLine(“{0} – {1}”, group.Key, group.Count()); Console.WriteLine(“———-“); foreach (var employee in group) { Console.WriteLine(employee.Name + “\t” + employee.Department); } } Console.WriteLine(); Console.WriteLine(); } } public class Employee { public int ID { get; set; } public string Name { get; set; } public string Gender { get; set; } public … Continue reading How Grouping working in Linq

Download All rdl in one sort from ssrs By Sql

Introduction People working on SSRS are well aware that “Report Manager” does not support downloading all the report files (.rdl files) at one go out-of-box. And I am sure that many of you might have come across this requirement some day or other. Hence, today I will share a simple handy script which would help you to download all the required report files at once. Implementation SSRS uses SQL Server to store it’s details as a backend and the Catalog table is used to store the report file in binary form. The below script simply pulls the report definition from … Continue reading Download All rdl in one sort from ssrs By Sql

Race Condition In C#

or example, You have two threads—one is responsible for opening a file and the other is responsible for writing to the file. It is important that you control the second thread so that it’s assured that the first thread has opened the file. If not, under some conditions the first thread will open the file, and the second thread will work fine; under other unpredictable conditions, the first thread won’t finish opening the file before the second thread tries to write to it, and you’ll throw an exception. This is a race condition. Example: Let’s look at the below example, … Continue reading Race Condition In C#