A DotNet Developer In Toronto
Discuss technologies, mostly Microsoft, DotNet, C#, WCF, WPF, Silverlight, jQuery, AJAX, SQL Server, SharePoint, BizTalk, JavaScript, SOA, Design Pattern, UML, Agile, Oracle, messaging, etc.
Sunday, 26 February 2017
nodeJS and AngularJS
I haven't used Visual Studio and .Net as a development tool for more than 2 years now... instead, everyday is AngularJS, Node, and mySQL
Thursday, 29 January 2015
First Andriod App run on my Samsung Galaxy S5
Run "Hello World" on your Android Smartphone
1. Install Android Studio on your computer
2. Enable Developer options on S5
3. Download and install Samsung USB driver, you should see it as following in the Device Manager of your computer
5. Create a "Hello World" project in Android Studio
6. Run it and choose running device, and then [OK]
7. I got error:
pkg: /data/local/tmp/com.example.yourname.helloworld
Failure
[INSTALL_FAILED_OLDER_SDK]
The reason is that, in my Samsung phone, the version of API is 19, while in Android Studio, the minSdkVersion is set to 21. To change this, open build.gradle (Module: app), locate defaultConfig:
defaultConfig {
applicationId "com.example.yourname.helloworld"
minSdkVersion 21
targetSdkVersion 21
versionCode
1
versionName
"1.0"
}
Change it to:
defaultConfig {
applicationId "com.example.yourname.helloworld"
minSdkVersion 19
targetSdkVersion 21
versionCode
1
versionName
"1.0"
}
Run it again, I see "Hello world!" on my phone!
If you still get the same error, you can further lower the version number, make sure the minSdkVersion is not lower than the API version of your Android phone.
I ran it on my Samsung Galaxy S5, and I would assume the above steps would be very similar on other Android Phones.
Tuesday, 29 May 2012
Windows 7 tip: Change [Shut down] to [Sleep] at Start Menu
There are many times that I want to make my computer
sleep instead of shuting it down, so it would be more convenient to show the
sleep button rather than shut down at Start Menu. Here is the way how to do it:
Right Click the Taskbar and select Properties.
This will open up the "Taskbar and Start
Menu Properties".
Goto the "Start Menu" Tab
At Power button action, change it to Sleep,
click OK to save it
Tuesday, 13 March 2012
MVC 3 client side TextBox Validation
1. In the model, add attributes notation
[Required(ErrorMessage="name is required")]
public string Name { get; set; }
2. In the View, add the following before Html.BeginForm
<script src="../../Scripts/jquery.validate.min.js" type="text/javascript"></script>
<script src="../../Scripts/jquery.validate.unobtrusive.min.js"
type="text/javascript"></script>
@{ Html.EnableClientValidation(); }
3. Also in the View, add validation message beside your TextBox
<div class="FormInput">
@Html.EditorFor(model => model.Name)
@Html.ValidationMessageFor(model => model.Name)
</div>
Sunday, 15 January 2012
MS SQL Server Isolation level explained
An isolation level determines the degree of data isolation between concurrent transactions. The default SQL
Server isolation level is Read Committed.
In the ascending order of isolation: Read
Uncommitted, Read Committed, Repeatable Read, Serializable.
Read uncommitted: dirty read,
you can read those that have been modified by other transaction but not yet
committed. It does not issue shared locks to prevent other transactions from
modifying data read by the current transaction.
Read committed: cannot read
data that has been modified but not committed by other transactions, this
prevents dirty reads. Data can be changed by other transactions between
individual statements within the current transaction, resulting nonrepeatable reads
or phantom data. Shared locks are only held for individual statements.
Repeatable read: cannot read
data that has been modified but not yet committed by other transactions and
that no other transactions can modify data that has been read by current
transaction until current transaction completes. Shared locks are placed on all
data read by each statement in the transaction and are held until the
transaction completes. This prevents other transactions from modifying any rows
that have been read by the current transaction. But other transactions can insert
new rows, so the query statement of current transaction could return unrepeatable
results. Shared locks are held to the end of a transaction instead of being
released at the end of each statement as READ COMMITTED.
Serializable: is the highest
level, where transactions are completely isolated from one another. It cannot
read data that has been modified but not yet committed by other transactions. No
other transactions can modify data that has been read by the current transaction
until the current transaction completes. Also, other transactions cannot insert
rows with key values that would fall in the range of keys read by any
statements in the current transaction until current transaction completes. Range
locks are placed in the range of key values that match the search conditions of
each statement executed in the transaction, this means that if any of the
statements in the current transaction are executed a second time, they will
read the same set of rows. The range locks are held until the transaction
completes.
A few ASP.NET, C# questions
Question: you
care building a setup for your application. The application contains a custom
control developed by you, which will be shared across multiple applications.
How should you package the custom control?
A: Package the control in a Merge Module (.msm) and add
the .msm file to a
Windows Installer project.
B: Package the control into a cabinet project (.cab) and
add the .cab file
to a Windows Installer project.
C: Create a separate directory for the control and then
package it in a
Windows Installer project along with the rest of the
project files.
D: Package the control as a Web setup project and create
a link to that
project from the Windows Installer project.
My answer: B
Question: If
you want to place a status bar control named 'statusBar1' at the bottom of your
windows Form, which of the following would be the correct property to set?
A. statusBar1.Dock = DockStyle.Bottom;
B. statusBar1.Lock = "Bottom";
C. Location(statusBar1) = DockStyle.Bottom;
D. statusBar1 = Placement.Down;
My answer: A
What namespaces
must you declare in order to use a SqlConnection object?
A. Import System.Data.Sql;
B. using System.Data.Sql;
C. using System.Data.SqlClient;
D. using Sql.Data;
My answer: C
Question: Which
type of DataSet is derived from the base DataSet class and then uses
information in an XML Schema file (.xsd file) in order to generate a new class?
A. Untyped DataSet
B. Typed DataSet
C. XML DataSet
D. XSD DataSet
My answer: B
You want to
accomplish the following with a Button Control:
1.) Add the button
2.) Add the Event Handler
3.) Trigger the event
which would be the correct segment of code to accomplish
these tasks?
A.
Button b = new Button(new EventHandler(onButtonAction));
b.clicked = True;
B.
Button b = new Button(new EventHandler(onButtonAction));
b.clicked(1);
C.
Button b = new Button();
b.Click += new ButtonEventHandler(onButtonAction);
b.PerformClick();
D.
Button b = new Button();
b.Click += new ButtonEventHandler(onButtonAction);
b.clicked = True;
My answer: C
Question: You
need to create a file name "File.txt" in the directory
"C:/data". How should you go about doing this?
A.
File fs = New File;
fs.Name = "File.txt";
fs.Directory = "C:/data";
fs.Create();
B.
FileStream fs =
File.Create("C:/data/File.txt");
C.
FileStream fs = New FileStream();
fs.Name = "File.txt";
fs.Directory = "C:/data";
fs.Create();
D.
Stream sw = File.Create("C:/data/File.txt");
My answer: B, but the directory must exists in advance
Which of the
following statements are TRUE about XML serialization?
I. XML serialization serializes only the public fields
and property values of an object into an XML stream.
II. XML serialization inlcude type information.
III. XML serialization requires a default
constructor to be declared in the class
that is to be serialized.
IV. XML serialization requires all properties that are to
be serialized as read/write properties. Read-only properties are not
serialized.
A. I
B. I and II
C. I, III and IV
D. All of the above
My answer: C
XML serialization by default doesn't serialize read-only
properties
It requires a parameterless constructor in order to allow
xml serialization to succeed
Question: The
following code is found in a windows Application:
this.openFileDialog1.Title = "Open File";
this.openFileDialog1.Filter = "Word Documents
(*.doc) | *.doc | Excel Spreadsheets (*.xls) | *.xls";
this.openFileDialog1.FilterIndex = 1;
this.openFileDialog1.CheckFileExists = true;
this.openFileDialog1.ShowReadOnly = false;
this.openFileDialog1.ShowDialog();
Which of the following statement is TRUE about this code
segment?
A. The code segment sets the Dialog Title to Open File
B. The code segment sets the default file type to Excel
Spreadsheets.
C. The code sets the File List box to Word documents and
Excel documents
D. A and C
E. All of the above
My answer: D
the code segment sets the default file type to Word
document
Question: Which of the statements below concerning literals is TRUE?
I. Data can be assigned to literals.
II. In certain cases, a suffix is added so that literals can perform the calculation in a much better way.
III. Strings can have many characters and are sometimes enclosed within double quotes.
a. I
b. II
c. I and II
d. I and III
e. all of above
My answer: e
update shared assembly
Shortly after releasing a new windows service, you discovered that there is a calculation error in a shared assembly the application uses. You corrected the error and are ready to install the new assembly on the client computers. how should you perform to quickly install your updated assembly?
My answer: Copy over the shared assembly and then use GACUTIL to install it into global assembly
?? null coalescing operator
.NET 3.5 questions:
Q1: What is the output of the following code?
A1:
int? indicates b and c are nullable types
Q2: what is the output of the following code?
Q1: What is the output of the following code?
int a = 20;
int? b = 30;
int? c = null;
Console.WriteLine(a + c ?? b);
result is 30
int? indicates b and c are nullable types
The result of 20+null is null.
?? operator checks whether the value of a+c is null, it returns a+c if it isn't null, returns b if it is null.
?? operator works for both reference and value types.
?? operator works for both reference and value types.
var s= "Hello";
s = 5;
s = 5++;
Console.WriteLine(s);
Cannot compile, error is "cannot implicitly convert
type 'int' to 'string'
Subscribe to:
Posts (Atom)