Showing posts with label c#. Show all posts
Showing posts with label c#. Show all posts

Tuesday, December 27, 2022

C# DateTime from Excel turns into float number

 In Excel, dates and times are stored as a floating point number representing the number of days since the epoch date of January 1, 1970. This means that when you read a date or time value from an Excel file into a C# DateTime object, you will need to convert the floating point value to a DateTime object.


Here is an example of how you could do this in C#:


// Assume that the Excel date value is stored in a variable called "excelDate" // Convert the Excel date value to a DateTime object DateTime dateTime = DateTime.FromOADate(excelDate); // You can also use the following syntax to achieve the same result: // DateTime dateTime = new DateTime((long)(excelDate * 86400000) + new DateTime(1970, 1, 1).Ticks);


In this example, the FromOADate method is used to convert the Excel date value to a DateTime object. This method is part of the System.DateTime struct and takes a floating point value representing the number of days since the epoch date.

Alternatively, you can use the Ticks property of the DateTime struct and some simple math to convert the Excel date value to a DateTime object. In this case, the value is first converted to a number of ticks (multiplying it by the number of ticks per day), and then the resulting ticks are



linq query to get maximum salary in employee list object

 Here is an example of how you could use LINQ (Language Integrated Query) to get the maximum salary in a list of employee objects in C#:


  using System.Linq;


// Assume that the list of employees is stored in a variable called "employees"


// Get the maximum salary from the list of employees

decimal maxSalary = employees.Max(e => e.Salary);


// You can also use the following syntax to achieve the same result:

// decimal maxSalary = (from e in employees select e.Salary).Max();



In this example, the Max method is used to get the maximum salary from the list of employees. The method takes a lambda expression that specifies the property to use for the comparison (in this case, the Salary property).


Alternatively, you can use a LINQ query to achieve the same result. The query uses the from and select clauses to specify the source collection and the property to select, and the Max method is used to get the maximum value.


Note that this code assumes that the employees list and the Employee class have already been defined and that the Employee class has a Salary property of type decimal. You will need to modify the code to match the structure of your own data.

Friday, July 27, 2012

Get count of checkboxlist selected items

this is single line of code that can be used to get the number of items selected in checkboxlist in asp.net with c#

int count= ChbProperty.Items.Cast<ListItem>().Count(li => li.Selected);

.net core

 Sure, here are 50 .NET Core architect interview questions along with answers: 1. **What is .NET Core, and how does it differ from the tradi...