Search This Blog
Monday, January 19, 2015
Thursday, January 15, 2015
ReadAllBytes C# Example
C# > Files > File Class > ReadAllBytes
Opens, reads the contents of the file into a byte array, and then closes the file.
Example
Read bytes from jpg file and display to PictureBox.
var bytes = File.ReadAllBytes("D:\\Pics\\1.jpg");
pictureBox1.Image = Image.FromStream(new System.IO.MemoryStream(bytes));
Etichete:
c#
C# File Class
C# > Files > File Class
Use the File class for:
- copy, move, rename, create, open, delete to a single file at a time.
- get and set file attributes.
Etichete:
c#
Tuesday, January 6, 2015
IsNumeric equivalent in LINQ example
C# > LINQ > IsNumeric
IsNumeric equivalent in LINQ example.
double value;
IsNumeric equivalent in LINQ example.
double value;
var total = (from DataRow dr in dataTable.Rows
where double.TryParse(dr["value"], out value)
select Convert.ToDouble(dr["value"])).Sum();
Etichete:
c#
Wednesday, December 24, 2014
Dependency Injection C# Example
Dependency injection promotes loose coupling of components by passing dependencies to an object rather than having an object instantiate its own dependencies.(http://www.blackwasp.co.uk/DependencyInjection.aspx)
Example
public interface ITruck
{
void Go(double distance);
}
public class Truck : ITruck
{
public double Consumption{ get; set; }
public void Go(double distance)
{
double necessary_fuel = Consumption * distance;
}
}
public interface IRoute
{
void AddTruck(ITruck dependency);
}
public class Route : IRoute
{
ITruck _truck;
public double Distance { get; set; }
public void AddTruck(ITruck truck)
{
_truck = truck;
}
public void TruckGo()
{
_truck.Go(Distance);
}
}
Route route = new Route();
route.Distance = 100;
Truck truck = new Truck();
truck.Consumption = 20;
route.AddTruck(truck);
route.TruckGo();
Etichete:
c#
C# System.Security AccessControl
C# > System.Security > AccessControl
With AccessControl you can control, access and audit security related actions on securable objects.
With AccessControl you can control, access and audit security related actions on securable objects.
Etichete:
c#
C# > System.Security
C# > System.Security
- NET Framework security system
- provide access to authentication
- provide crytographic services
- control access to operations based on policy
- rights management of application-created content
Etichete:
c#
Subscribe to:
Posts (Atom)