Saturday, April 12, 2014
Make your Ubuntu Virtualbox increase it's screen resolution on Windows
1. Make sure you login with an administrative rights.
2. Open the Terminal. (can be opened by pressing 'Ctrl' + 'Alt' + 'T')
3. Type this command "sudo apt-get install virtualbox-guest-dkms" then press Enter.
4. After installation is complete, restart your Ubuntu on the Virtualbox.
UPDATE (for Ubuntu 14.04 LTS):
On step 3, you would run this command "sudo apt-get install virtualbox-guest-x11" instead.
After restart, you would notice that your Ubuntu screen resolution would now adopt to your Host OS screen.
Thursday, February 4, 2010
C# - Change compilation debug value of the configuration file at runtime
Configuration config = WebConfigurationManager.OpenWebConfiguration("/WebPersonalExercises"); CompilationSection compSection = ((CompilationSection)(config.GetSection("system.web/compilation"))); compSection.Debug = true; config.Save();
Please note that there might be times that this section is locked, so it is always helpful to check them first. Below is a revision C# code snippet to show that.
Configuration config = WebConfigurationManager.OpenWebConfiguration("/WebPersonalExercises"); CompilationSection compSection = ((CompilationSection)(config.GetSection("system.web/compilation"))); compSection.Debug = true; if (!(compileSection.SectionInformation.IsLocked)) { config.Save(); }
Tuesday, February 2, 2010
C# - Manipulating the appSettings section of the configuration file at runtime
Adding a new appSetting value:
Configuration config = WebConfigurationManager.OpenWebConfiguration("/WebPersonalExercises"); AppSettingsSection appSection = ((AppSettingsSection)(config.GetSection("appSettings"))); KeyValueConfigurationCollection keyVal = appSection.Settings; keyVal.Add("myNewValue", "value" + ++intCounter); config.Save();
Removing the value:
Configuration config = WebConfigurationManager.OpenWebConfiguration("/WebPersonalExercises"); AppSettingsSection appSection = ((AppSettingsSection)(config.GetSection("appSettings"))); KeyValueConfigurationCollection keyVal = appSection.Settings; keyVal.Remove("myNewValue"); config.Save();
Note that if you add the same appSetting key multiple times, it would be presented in the file like this (concatenated with a comma separator):
<appSettings> <add key="myNewValue" value="value1,value2,value3"/> </appSettings>
But when you call the remove method, all of the appSetting key-value would be removed, regardless of how many times you add the same appSetting key of different values.
Wednesday, January 27, 2010
Data Type Range: Floating-Point and Decimal Data Types
- float - based on System.Single
- 32-bit single-precision floating point number between -3.402832 x 1038 and -1.401298 / 1045 (for negative values) and between 1.401298 / 1045 and 3.402832 x 1038 (for positive values)
- numeric literal - F or f. e.g. float price = 345.45F;
- double - based on System.Double
- 64-bit double-precision floating point number between -1.79769313486231570 x 10308 and -4.94065645841246544 / 10324 (for negative values) and between 4.94065645841246544 x 10324 and 1.79769313486231570 x 10308
- numeric literal - D or d. e.g. double salary = 2500.50D;
- decimal - based on System.Decimal
- 128-bit number between -79,228,162,514,264,337,593,543,950,335 and 79,228,162,514,264,337,593,543,950,335 with no decimal places and between -7.9228162514264337593543950335 and 7.9228162514264337593543950335 with up to 28 decimal places
- holds numbers of lesser range than floating points but with greater precision
- numeric literal - M or m. e.g. decimal width = 3.68M;
More of c# literal could be found here.
Tuesday, January 26, 2010
Data Type Range: Integer
I've been developing C# for so many years. As I work through my certification (a goal for a very long time :D) I always miss the very basic things about C#. For example, I could not really differentiate the Integer data types with their range and size. So this post serves a my own reminder for that.
- sbyte - based on System.SByte
- 8-bit signed integer between -128 and 127
- byte - based on System.Byte
- 8-bit integer between 0 and 255
- short - based on System.Int16
- 16-bit integer between -32,768 and 32,767
- ushort - based on System.Int16
- 16-bit unsigned integer between 0 and 65,535
- int - based on System.Int32
- 32-bit integer between -2,147,483,648 and 2,147,483,647
- uint - based on System.Int32
- 32-bit unsigned integer between 0 and 4,294,967,295
- long - based on System.Int64
- 64-bit integer between -9,223,372,036,854,775,808 and 9,223,372,036,854,775,807
- ulong - based on System.Int64
- 64-bit unsigned integer between 0 and 18,446,744,073,709,551,615
We have to take note on the memory requirement and performance upon using these data type as we code. int requires twice as much storage of space (4 bytes) than short (2 bytes).
But as a recommendation we have to use int or long because they are more efficient than byte and short because .Net represents numbers as a 32-bit or a 64-bit values. Unless you have a valid concern about memory usage, then you could use the specific data type for your needs.
Thursday, November 19, 2009
Explicit interface implementation in VB.NET
Public Interface ISample Sub invokeMe(data as String) End Interface
Explicit implementation of the interface:
Public Class ExplicitClass Implements ISample Private Sub invokeMe(data as String) Implements ISample.invokeMe Console.WriteLine(data) End Sub End Class
Thursday, July 31, 2008
Difference between Implicit and Explicit implementation of an Interface
The Scenario:
While doing an API for a project, a colleague of mine ask me about the difference between implicitly and explicitly implementing an interface in C#. In all of the code (in our API), I did an explicit implementation of the interface with the sole purpose for the developers to use the API to code through interface. By doing this, it would promote a loosely coupled implementation between the client code and the API. Here is an example that I used to help me explain the benefit of doing this.
The Interface:
interface ISample { void invokeMe(string data); }
Implicit implementation of the interface:
public class ImplicitClass : ISample { #region ISample Members public void invokeMe(string data) { Console.WriteLine(data); } #endregion }
Explicit implementation of the interface:
public class ExplicitClass : ISample { #region ISample Members void ISample.invokeMe(string data) { Console.WriteLine(data); } #endregion }
The Client Code:
static void Main(string[] args) { // using Implicit implementation ISample isam; isam = new ImplicitClass(); isam.invokeMe("Hello implicit world by Interface!"); // using Explicit implementation ISample isam1; isam1 = new ExplicitClass(); isam1.invokeMe("Hello explicit world by Interface!"); // using the concrete class on an implicitly implemented class ImplicitClass imp = new ImplicitClass(); imp.invokeMe("Hello world by the implicit concrete class!"); // using the concrete class on an explicitly implemented class ExplicitClass exp = new ExplicitClass(); // This code here would not even compile, // the class could not access the implemented method. exp.invokeMe("Hello world by the explicit concrete class!"); Console.ReadLine(); }
Summary:
Using implicit implemetation could not force any client code to implement a program-by-interface because as you could see, implemented method can be invoked directly in the concrete class. By using explicit implmentation the client code must program-by-interface (access through interface) to invoke the method.
You might be asking why to program-by-interface? Well, the answer is to promote a loosely coupled implementation. This technique allow server developers to enforce separation of the interface from the implementation.