SlideShare une entreprise Scribd logo
1  sur  18
Tips and Tricks of Developing
.NET Application
Joni
Applied Technology Laboratories
Bina Nusantara University
Agenda
 General Best Practices
 ASP .NET Specific
 Windows Forms Specific
 Resources
General Best Practices
 Looping optimization
ArrayList list = new ArrayList();ArrayList list = new ArrayList();
for(int ifor(int i == 0; i0; i << list.Count; i++)list.Count; i++)
{{
MyObject o = (MyObject)list[i];MyObject o = (MyObject)list[i];
o.DoSomeWork();o.DoSomeWork();
}}
ArrayList list = new ArrayList();ArrayList list = new ArrayList();
MyObject oMyObject o = null;= null;
for(int ifor(int i == 00, n =, n = list.Count; ilist.Count; i << nn; i++); i++)
{{
o = (MyObject)list[i];o = (MyObject)list[i];
o.DoSomeWork();o.DoSomeWork();
}}
General Best Practices
 Use proper casting, avoid polymorphic call
String s = “Hello world”;String s = “Hello world”;
Session[“key”] = s;Session[“key”] = s;
……
String result = Session[“key”].ToString();String result = Session[“key”].ToString();
String s = “Hello world”;String s = “Hello world”;
Session[“key”] = s;Session[“key”] = s;
……
String result =String result = (string)(string)Session[“key”];Session[“key”];
General Best Practices
 Acquire, Execute, Release pattern
 Works with any IDisposable object
 Data access classes, streams, text readers and writers,
network classes, etc.
using (Resource res = new Resource()) {using (Resource res = new Resource()) {
res.DoWork();res.DoWork();
}}
Resource res = new Resource(...);Resource res = new Resource(...);
try {try {
res.DoWork();res.DoWork();
}}
finally {finally {
if (res != null) ((IDisposable)res).Dispose();if (res != null) ((IDisposable)res).Dispose();
}}
General Best Practices
static void Copy(string sourceName, string destName) {static void Copy(string sourceName, string destName) {
Stream input = File.OpenRead(sourceName);Stream input = File.OpenRead(sourceName);
Stream output = File.Create(destName);Stream output = File.Create(destName);
byte[] b = new byte[65536];byte[] b = new byte[65536];
int n;int n;
while ((n = input.Read(b, 0, b.Length)) != 0) {while ((n = input.Read(b, 0, b.Length)) != 0) {
output.Write(b, 0, n);output.Write(b, 0, n);
}}
output.Close();output.Close();
input.Close();input.Close();
}}
static void Copy(string sourceName, string destName) {static void Copy(string sourceName, string destName) {
Stream input = File.OpenRead(sourceName);Stream input = File.OpenRead(sourceName);
try {try {
Stream output = File.Create(destName);Stream output = File.Create(destName);
try {try {
byte[] b = new byte[65536];byte[] b = new byte[65536];
int n;int n;
while ((n = input.Read(b, 0, b.Length)) != 0) {while ((n = input.Read(b, 0, b.Length)) != 0) {
output.Write(b, 0, n);output.Write(b, 0, n);
}}
}}
finally {finally {
output.Close();output.Close();
}}
}}
finally {finally {
input.Close();input.Close();
}}
}}
static void Copy(string sourceName, string destName) {static void Copy(string sourceName, string destName) {
using (Stream input = File.OpenRead(sourceName))using (Stream input = File.OpenRead(sourceName))
using (Stream output = File.Create(destName)) {using (Stream output = File.Create(destName)) {
byte[] b = new byte[65536];byte[] b = new byte[65536];
int n;int n;
while ((n = input.Read(b, 0, b.Length)) != 0) {while ((n = input.Read(b, 0, b.Length)) != 0) {
output.Write(b, 0, n);output.Write(b, 0, n);
}}
}}
}}
 In time critical application, avoid using
‘foreach’
General Best Practices
public static void Main(string[] args) {public static void Main(string[] args) {
foreach (string s in args) Console.WriteLine(s);foreach (string s in args) Console.WriteLine(s);
}}
public static void Main(string[] args) {public static void Main(string[] args) {
for(int i = 0, n = args.Length; i < n; i++)for(int i = 0, n = args.Length; i < n; i++)
Console.WriteLine(args[i]);Console.WriteLine(args[i]);
}}
General Best Practices
public ArrayList GetList()public ArrayList GetList()
{{
ArrayList temp = new ArrayList();ArrayList temp = new ArrayList();
……
return temp;return temp;
}}
……
public void DoWpublic void DoWoork()rk()
{{
ArrayList list = new ArrayList();ArrayList list = new ArrayList();
list = GetList();list = GetList();
}}
 Avoid unnecessary object instantiation
public ArrayList GetList()public ArrayList GetList()
{{
ArrayList temp = new ArrayList();ArrayList temp = new ArrayList();
……
return temp;return temp;
}}
……
public void DoWork()public void DoWork()
{{
ArrayList list =ArrayList list = nullnull;;
list = GetList();list = GetList();
}}
public ArrayList GetList()public ArrayList GetList()
{{
ArrayList temp = new ArrayList();ArrayList temp = new ArrayList();
……
return temp;return temp;
}}
……
public void DoWork()public void DoWork()
{{
ArrayList list =ArrayList list = GetList()GetList();;
}}
General Best Practices
 Use StringBuilder for string manipulation
publicpublic stringstring ProcessLongText()ProcessLongText()
{{
string text = “How are you?”;string text = “How are you?”;
string s = text;string s = text;
for(int i = 0; i < 1000; i++)for(int i = 0; i < 1000; i++)
{{
s += text;s += text;
}}
return s;return s;
}}
public string ProcessLongText()public string ProcessLongText()
{{
string text = “How are you?”;string text = “How are you?”;
StringBuilder s = new StringBuilder(text);StringBuilder s = new StringBuilder(text);
for(int i = 0; i < 1000; i++)for(int i = 0; i < 1000; i++)
{{
s.Append(text);s.Append(text);
}}
return s.ToString();return s.ToString();
}}
General Best Practices
 Do not rely on exceptions in your code
try {try {
result = 100 / num;result = 100 / num;
}}
catch (Exception e) {catch (Exception e) {
result = 0;result = 0;
}}
if (num != 0)if (num != 0)
result = 100 / num;result = 100 / num;
elseelse
result = 0;result = 0;
General Best Practices
 Don’t reinvent the wheel, unless you are super
programmer, use existing class library
 Use Data Access Application Block for
accessing database
objectobject resultresult ==
SqlHelper.ExecuteScalar(connectionString,SqlHelper.ExecuteScalar(connectionString,
CommandType.StoredProcedure, spName, sqlParameters);CommandType.StoredProcedure, spName, sqlParameters);
ASP .NET Specific
 Disable ViewState if not used
 Use output cache to speed-up performance
 Disable SessionState if not used
 Avoid unnecessary round trips to the server
 Use Page.IsPostBack to avoid performing unnecessary
processing on a round trip
 Consider disabling AutoEventWireup for your application
<%@ OutputCache Duration=“60" VaryByParam="None" Shared="true" %><%@ OutputCache Duration=“60" VaryByParam="None" Shared="true" %>
<page enableSessionState="true|false|ReadOnly” /><page enableSessionState="true|false|ReadOnly” />
ASP .NET Specific
 Be sure to disable debug mode
 Avoid using DataBinder.Eval
<%# DataBinder.Eval(Container.DataItem, “myfield") %><%# DataBinder.Eval(Container.DataItem, “myfield") %>
<%#<%# ((DataRowView)Container.DataItem)[“myfield”].ToString()((DataRowView)Container.DataItem)[“myfield”].ToString() %>%>
<compilation defaultLanguage="c#"<compilation defaultLanguage="c#" debug=“debug=“falsefalse"" />/>
ASP .NET Specific
 Override method, instead of attaching delegate
to it
private void InitializeComponent()private void InitializeComponent()
{{
this.Load += new System.EventHandler(this.Page_Load);this.Load += new System.EventHandler(this.Page_Load);
}}
private void Page_Load(object sender, System.EventArgs e)private void Page_Load(object sender, System.EventArgs e)
{{
……
}}
protectedprotected overrideoverride voidvoid OnOnLoad(System.EventArgs e)Load(System.EventArgs e)
{{
……
}}
ASP .NET Specific
 Use IDataReader instead of DataSet
 Use Repeater instead of DataGrid (if possible)
 Use the HttpServerUtility.Transfer method to
redirect between pages in the same application
 Use early binding in Visual Basic .NET or
JScript code
<%@ Page Language="VB" Strict="true" %><%@ Page Language="VB" Strict="true" %>
Windows Forms Specific
 Use multithreading appropriately to make your
application more responsive
 Windows Forms uses the single-threaded apartment
(STA) model because Windows Forms is based on
native Win32 windows that are inherently apartment-
threaded. The STA model requires that any methods
on a control that need to be called from outside the
control's creation thread must be marshaled to
(executed on) the control's creation thread
Windows Forms Specific
if(this.InvokeRequired)if(this.InvokeRequired)
{{
this.Invoke(this.Invoke(
newnew EventHandler(this.DisableButton),EventHandler(this.DisableButton),
new object[] {new object[] { null, EventArgs.Emptynull, EventArgs.Empty }}
););
}}
Resources
http://www.asp.net/
http://www.gotdotnet.com/
http://www.microsoft.com/resources/practices/
developer.mspx

Contenu connexe

Tendances

Python Performance 101
Python Performance 101Python Performance 101
Python Performance 101Ankur Gupta
 
関数潮流(Function Tendency)
関数潮流(Function Tendency)関数潮流(Function Tendency)
関数潮流(Function Tendency)riue
 
The Ring programming language version 1.8 book - Part 75 of 202
The Ring programming language version 1.8 book - Part 75 of 202The Ring programming language version 1.8 book - Part 75 of 202
The Ring programming language version 1.8 book - Part 75 of 202Mahmoud Samir Fayed
 
The Ring programming language version 1.7 book - Part 73 of 196
The Ring programming language version 1.7 book - Part 73 of 196The Ring programming language version 1.7 book - Part 73 of 196
The Ring programming language version 1.7 book - Part 73 of 196Mahmoud Samir Fayed
 
GreenDao Introduction
GreenDao IntroductionGreenDao Introduction
GreenDao IntroductionBooch Lin
 
The Ring programming language version 1.5.2 book - Part 44 of 181
The Ring programming language version 1.5.2 book - Part 44 of 181The Ring programming language version 1.5.2 book - Part 44 of 181
The Ring programming language version 1.5.2 book - Part 44 of 181Mahmoud Samir Fayed
 
JavaScript Proxy (ES6)
JavaScript Proxy (ES6)JavaScript Proxy (ES6)
JavaScript Proxy (ES6)Aries Cs
 
Google Guava - Core libraries for Java & Android
Google Guava - Core libraries for Java & AndroidGoogle Guava - Core libraries for Java & Android
Google Guava - Core libraries for Java & AndroidJordi Gerona
 
New SPL Features in PHP 5.3
New SPL Features in PHP 5.3New SPL Features in PHP 5.3
New SPL Features in PHP 5.3Matthew Turland
 
ITT 2015 - Saul Mora - Object Oriented Function Programming
ITT 2015 - Saul Mora - Object Oriented Function ProgrammingITT 2015 - Saul Mora - Object Oriented Function Programming
ITT 2015 - Saul Mora - Object Oriented Function ProgrammingIstanbul Tech Talks
 
Building Real Time Systems on MongoDB Using the Oplog at Stripe
Building Real Time Systems on MongoDB Using the Oplog at StripeBuilding Real Time Systems on MongoDB Using the Oplog at Stripe
Building Real Time Systems on MongoDB Using the Oplog at StripeStripe
 
Jggug 2010 330 Grails 1.3 観察
Jggug 2010 330 Grails 1.3 観察Jggug 2010 330 Grails 1.3 観察
Jggug 2010 330 Grails 1.3 観察Tsuyoshi Yamamoto
 
Building Real Time Systems on MongoDB Using the Oplog at Stripe
Building Real Time Systems on MongoDB Using the Oplog at StripeBuilding Real Time Systems on MongoDB Using the Oplog at Stripe
Building Real Time Systems on MongoDB Using the Oplog at StripeMongoDB
 
ORMLite Android
ORMLite AndroidORMLite Android
ORMLite Android哲偉 楊
 
Mcs011 solved assignment by divya singh
Mcs011 solved assignment by divya singhMcs011 solved assignment by divya singh
Mcs011 solved assignment by divya singhDIVYA SINGH
 

Tendances (20)

Python Performance 101
Python Performance 101Python Performance 101
Python Performance 101
 
はじめてのGroovy
はじめてのGroovyはじめてのGroovy
はじめてのGroovy
 
関数潮流(Function Tendency)
関数潮流(Function Tendency)関数潮流(Function Tendency)
関数潮流(Function Tendency)
 
The Ring programming language version 1.8 book - Part 75 of 202
The Ring programming language version 1.8 book - Part 75 of 202The Ring programming language version 1.8 book - Part 75 of 202
The Ring programming language version 1.8 book - Part 75 of 202
 
The Ring programming language version 1.7 book - Part 73 of 196
The Ring programming language version 1.7 book - Part 73 of 196The Ring programming language version 1.7 book - Part 73 of 196
The Ring programming language version 1.7 book - Part 73 of 196
 
GreenDao Introduction
GreenDao IntroductionGreenDao Introduction
GreenDao Introduction
 
The Ring programming language version 1.5.2 book - Part 44 of 181
The Ring programming language version 1.5.2 book - Part 44 of 181The Ring programming language version 1.5.2 book - Part 44 of 181
The Ring programming language version 1.5.2 book - Part 44 of 181
 
JavaScript Proxy (ES6)
JavaScript Proxy (ES6)JavaScript Proxy (ES6)
JavaScript Proxy (ES6)
 
Google Guava - Core libraries for Java & Android
Google Guava - Core libraries for Java & AndroidGoogle Guava - Core libraries for Java & Android
Google Guava - Core libraries for Java & Android
 
Grails queries
Grails   queriesGrails   queries
Grails queries
 
Introduzione a C#
Introduzione a C#Introduzione a C#
Introduzione a C#
 
New SPL Features in PHP 5.3
New SPL Features in PHP 5.3New SPL Features in PHP 5.3
New SPL Features in PHP 5.3
 
ITT 2015 - Saul Mora - Object Oriented Function Programming
ITT 2015 - Saul Mora - Object Oriented Function ProgrammingITT 2015 - Saul Mora - Object Oriented Function Programming
ITT 2015 - Saul Mora - Object Oriented Function Programming
 
mobl
moblmobl
mobl
 
Building Real Time Systems on MongoDB Using the Oplog at Stripe
Building Real Time Systems on MongoDB Using the Oplog at StripeBuilding Real Time Systems on MongoDB Using the Oplog at Stripe
Building Real Time Systems on MongoDB Using the Oplog at Stripe
 
Jggug 2010 330 Grails 1.3 観察
Jggug 2010 330 Grails 1.3 観察Jggug 2010 330 Grails 1.3 観察
Jggug 2010 330 Grails 1.3 観察
 
Spl Not A Bridge Too Far phpNW09
Spl Not A Bridge Too Far phpNW09Spl Not A Bridge Too Far phpNW09
Spl Not A Bridge Too Far phpNW09
 
Building Real Time Systems on MongoDB Using the Oplog at Stripe
Building Real Time Systems on MongoDB Using the Oplog at StripeBuilding Real Time Systems on MongoDB Using the Oplog at Stripe
Building Real Time Systems on MongoDB Using the Oplog at Stripe
 
ORMLite Android
ORMLite AndroidORMLite Android
ORMLite Android
 
Mcs011 solved assignment by divya singh
Mcs011 solved assignment by divya singhMcs011 solved assignment by divya singh
Mcs011 solved assignment by divya singh
 

Similaire à Tips and Tricks of Developing .NET Application

Refactoring to Macros with Clojure
Refactoring to Macros with ClojureRefactoring to Macros with Clojure
Refactoring to Macros with ClojureDmitry Buzdin
 
CBSE Class XII Comp sc practical file
CBSE Class XII Comp sc practical fileCBSE Class XII Comp sc practical file
CBSE Class XII Comp sc practical filePranav Ghildiyal
 
TypeScript Introduction
TypeScript IntroductionTypeScript Introduction
TypeScript IntroductionDmitry Sheiko
 
JAVA OOP project; desperately need help asap im begging.Been stuck.pdf
JAVA OOP project; desperately need help asap im begging.Been stuck.pdfJAVA OOP project; desperately need help asap im begging.Been stuck.pdf
JAVA OOP project; desperately need help asap im begging.Been stuck.pdffantasiatheoutofthef
 
Scala vs Java 8 in a Java 8 World
Scala vs Java 8 in a Java 8 WorldScala vs Java 8 in a Java 8 World
Scala vs Java 8 in a Java 8 WorldBTI360
 
Imugi: Compiler made with Python
Imugi: Compiler made with PythonImugi: Compiler made with Python
Imugi: Compiler made with PythonHan Lee
 
C# 6 and 7 and Futures 20180607
C# 6 and 7 and Futures 20180607C# 6 and 7 and Futures 20180607
C# 6 and 7 and Futures 20180607Kevin Hazzard
 
OrderTest.javapublic class OrderTest {       Get an arra.pdf
OrderTest.javapublic class OrderTest {         Get an arra.pdfOrderTest.javapublic class OrderTest {         Get an arra.pdf
OrderTest.javapublic class OrderTest {       Get an arra.pdfakkhan101
 
Java Unicode with Cool GUI Examples
Java Unicode with Cool GUI ExamplesJava Unicode with Cool GUI Examples
Java Unicode with Cool GUI ExamplesOXUS 20
 
Java Unicode with Live GUI Examples
Java Unicode with Live GUI ExamplesJava Unicode with Live GUI Examples
Java Unicode with Live GUI ExamplesAbdul Rahman Sherzad
 
Productive Programming in Groovy
Productive Programming in GroovyProductive Programming in Groovy
Productive Programming in GroovyGanesh Samarthyam
 
The Ring programming language version 1.5.3 book - Part 44 of 184
The Ring programming language version 1.5.3 book - Part 44 of 184The Ring programming language version 1.5.3 book - Part 44 of 184
The Ring programming language version 1.5.3 book - Part 44 of 184Mahmoud Samir Fayed
 
The Ring programming language version 1.5.3 book - Part 54 of 184
The Ring programming language version 1.5.3 book - Part 54 of 184The Ring programming language version 1.5.3 book - Part 54 of 184
The Ring programming language version 1.5.3 book - Part 54 of 184Mahmoud Samir Fayed
 

Similaire à Tips and Tricks of Developing .NET Application (20)

Jason parsing
Jason parsingJason parsing
Jason parsing
 
Refactoring to Macros with Clojure
Refactoring to Macros with ClojureRefactoring to Macros with Clojure
Refactoring to Macros with Clojure
 
CBSE Class XII Comp sc practical file
CBSE Class XII Comp sc practical fileCBSE Class XII Comp sc practical file
CBSE Class XII Comp sc practical file
 
Elm: give it a try
Elm: give it a tryElm: give it a try
Elm: give it a try
 
TypeScript Introduction
TypeScript IntroductionTypeScript Introduction
TypeScript Introduction
 
Java Generics
Java GenericsJava Generics
Java Generics
 
JAVA OOP project; desperately need help asap im begging.Been stuck.pdf
JAVA OOP project; desperately need help asap im begging.Been stuck.pdfJAVA OOP project; desperately need help asap im begging.Been stuck.pdf
JAVA OOP project; desperately need help asap im begging.Been stuck.pdf
 
Scala vs Java 8 in a Java 8 World
Scala vs Java 8 in a Java 8 WorldScala vs Java 8 in a Java 8 World
Scala vs Java 8 in a Java 8 World
 
Java programs
Java programsJava programs
Java programs
 
What's New In C# 7
What's New In C# 7What's New In C# 7
What's New In C# 7
 
Imugi: Compiler made with Python
Imugi: Compiler made with PythonImugi: Compiler made with Python
Imugi: Compiler made with Python
 
C# 6 and 7 and Futures 20180607
C# 6 and 7 and Futures 20180607C# 6 and 7 and Futures 20180607
C# 6 and 7 and Futures 20180607
 
OrderTest.javapublic class OrderTest {       Get an arra.pdf
OrderTest.javapublic class OrderTest {         Get an arra.pdfOrderTest.javapublic class OrderTest {         Get an arra.pdf
OrderTest.javapublic class OrderTest {       Get an arra.pdf
 
SDC - Einführung in Scala
SDC - Einführung in ScalaSDC - Einführung in Scala
SDC - Einführung in Scala
 
Java Unicode with Cool GUI Examples
Java Unicode with Cool GUI ExamplesJava Unicode with Cool GUI Examples
Java Unicode with Cool GUI Examples
 
Java Unicode with Live GUI Examples
Java Unicode with Live GUI ExamplesJava Unicode with Live GUI Examples
Java Unicode with Live GUI Examples
 
Scala 2 + 2 > 4
Scala 2 + 2 > 4Scala 2 + 2 > 4
Scala 2 + 2 > 4
 
Productive Programming in Groovy
Productive Programming in GroovyProductive Programming in Groovy
Productive Programming in Groovy
 
The Ring programming language version 1.5.3 book - Part 44 of 184
The Ring programming language version 1.5.3 book - Part 44 of 184The Ring programming language version 1.5.3 book - Part 44 of 184
The Ring programming language version 1.5.3 book - Part 44 of 184
 
The Ring programming language version 1.5.3 book - Part 54 of 184
The Ring programming language version 1.5.3 book - Part 54 of 184The Ring programming language version 1.5.3 book - Part 54 of 184
The Ring programming language version 1.5.3 book - Part 54 of 184
 

Plus de Joni

ASP.NET Core の ​ パフォーマンスを支える ​ I/O Pipeline と Channel
ASP.NET Core の ​ パフォーマンスを支える ​ I/O Pipeline と ChannelASP.NET Core の ​ パフォーマンスを支える ​ I/O Pipeline と Channel
ASP.NET Core の ​ パフォーマンスを支える ​ I/O Pipeline と ChannelJoni
 
.NET Framework で ​C# 8って使える? ​YESとNO!
.NET Framework で ​C# 8って使える? ​YESとNO!.NET Framework で ​C# 8って使える? ​YESとNO!
.NET Framework で ​C# 8って使える? ​YESとNO!Joni
 
.NET Core 3.0 で Blazor を使用した​フルスタック C# Web アプリ​の構築
.NET Core 3.0 で Blazor を使用した​フルスタック C# Web アプリ​の構築.NET Core 3.0 で Blazor を使用した​フルスタック C# Web アプリ​の構築
.NET Core 3.0 で Blazor を使用した​フルスタック C# Web アプリ​の構築Joni
 
Fiddler 使ってますか?
Fiddler 使ってますか?Fiddler 使ってますか?
Fiddler 使ってますか?Joni
 
Fukuoka.NET Conf 2018: 挑み続ける!Dockerコンテナによる ASP.NET Core アプリケーション開発事例
Fukuoka.NET Conf 2018: 挑み続ける!Dockerコンテナによる ASP.NET Core アプリケーション開発事例Fukuoka.NET Conf 2018: 挑み続ける!Dockerコンテナによる ASP.NET Core アプリケーション開発事例
Fukuoka.NET Conf 2018: 挑み続ける!Dockerコンテナによる ASP.NET Core アプリケーション開発事例Joni
 
ASP.NET パフォーマンス改善
ASP.NET パフォーマンス改善ASP.NET パフォーマンス改善
ASP.NET パフォーマンス改善Joni
 
Introduction to .NET
Introduction to .NETIntroduction to .NET
Introduction to .NETJoni
 
Introduction to Html
Introduction to HtmlIntroduction to Html
Introduction to HtmlJoni
 
Asp #1
Asp #1Asp #1
Asp #1Joni
 
Introduction to ASP.NET
Introduction to ASP.NETIntroduction to ASP.NET
Introduction to ASP.NETJoni
 
Asp #2
Asp #2Asp #2
Asp #2Joni
 
ASP.NET MVCはNullReferenceExceptionを潰している件
ASP.NET MVCはNullReferenceExceptionを潰している件ASP.NET MVCはNullReferenceExceptionを潰している件
ASP.NET MVCはNullReferenceExceptionを潰している件Joni
 

Plus de Joni (13)

ASP.NET Core の ​ パフォーマンスを支える ​ I/O Pipeline と Channel
ASP.NET Core の ​ パフォーマンスを支える ​ I/O Pipeline と ChannelASP.NET Core の ​ パフォーマンスを支える ​ I/O Pipeline と Channel
ASP.NET Core の ​ パフォーマンスを支える ​ I/O Pipeline と Channel
 
.NET Framework で ​C# 8って使える? ​YESとNO!
.NET Framework で ​C# 8って使える? ​YESとNO!.NET Framework で ​C# 8って使える? ​YESとNO!
.NET Framework で ​C# 8って使える? ​YESとNO!
 
.NET Core 3.0 で Blazor を使用した​フルスタック C# Web アプリ​の構築
.NET Core 3.0 で Blazor を使用した​フルスタック C# Web アプリ​の構築.NET Core 3.0 で Blazor を使用した​フルスタック C# Web アプリ​の構築
.NET Core 3.0 で Blazor を使用した​フルスタック C# Web アプリ​の構築
 
Fiddler 使ってますか?
Fiddler 使ってますか?Fiddler 使ってますか?
Fiddler 使ってますか?
 
Fukuoka.NET Conf 2018: 挑み続ける!Dockerコンテナによる ASP.NET Core アプリケーション開発事例
Fukuoka.NET Conf 2018: 挑み続ける!Dockerコンテナによる ASP.NET Core アプリケーション開発事例Fukuoka.NET Conf 2018: 挑み続ける!Dockerコンテナによる ASP.NET Core アプリケーション開発事例
Fukuoka.NET Conf 2018: 挑み続ける!Dockerコンテナによる ASP.NET Core アプリケーション開発事例
 
ASP.NET パフォーマンス改善
ASP.NET パフォーマンス改善ASP.NET パフォーマンス改善
ASP.NET パフォーマンス改善
 
Introduction to .NET
Introduction to .NETIntroduction to .NET
Introduction to .NET
 
Introduction to Html
Introduction to HtmlIntroduction to Html
Introduction to Html
 
C#
C#C#
C#
 
Asp #1
Asp #1Asp #1
Asp #1
 
Introduction to ASP.NET
Introduction to ASP.NETIntroduction to ASP.NET
Introduction to ASP.NET
 
Asp #2
Asp #2Asp #2
Asp #2
 
ASP.NET MVCはNullReferenceExceptionを潰している件
ASP.NET MVCはNullReferenceExceptionを潰している件ASP.NET MVCはNullReferenceExceptionを潰している件
ASP.NET MVCはNullReferenceExceptionを潰している件
 

Dernier

8257 interfacing 2 in microprocessor for btech students
8257 interfacing 2 in microprocessor for btech students8257 interfacing 2 in microprocessor for btech students
8257 interfacing 2 in microprocessor for btech studentsHimanshiGarg82
 
Introducing Microsoft’s new Enterprise Work Management (EWM) Solution
Introducing Microsoft’s new Enterprise Work Management (EWM) SolutionIntroducing Microsoft’s new Enterprise Work Management (EWM) Solution
Introducing Microsoft’s new Enterprise Work Management (EWM) SolutionOnePlan Solutions
 
How To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected WorkerHow To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected WorkerThousandEyes
 
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...SelfMade bd
 
Pharm-D Biostatistics and Research methodology
Pharm-D Biostatistics and Research methodologyPharm-D Biostatistics and Research methodology
Pharm-D Biostatistics and Research methodologyAnusha Are
 
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsUnveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsAlberto González Trastoy
 
Exploring the Best Video Editing App.pdf
Exploring the Best Video Editing App.pdfExploring the Best Video Editing App.pdf
Exploring the Best Video Editing App.pdfproinshot.com
 
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...Health
 
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️Delhi Call girls
 
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfLearn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfkalichargn70th171
 
TECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providerTECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providermohitmore19
 
Right Money Management App For Your Financial Goals
Right Money Management App For Your Financial GoalsRight Money Management App For Your Financial Goals
Right Money Management App For Your Financial GoalsJhone kinadey
 
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...Shane Coughlan
 
ManageIQ - Sprint 236 Review - Slide Deck
ManageIQ - Sprint 236 Review - Slide DeckManageIQ - Sprint 236 Review - Slide Deck
ManageIQ - Sprint 236 Review - Slide DeckManageIQ
 
The Guide to Integrating Generative AI into Unified Continuous Testing Platfo...
The Guide to Integrating Generative AI into Unified Continuous Testing Platfo...The Guide to Integrating Generative AI into Unified Continuous Testing Platfo...
The Guide to Integrating Generative AI into Unified Continuous Testing Platfo...kalichargn70th171
 
LEVEL 5 - SESSION 1 2023 (1).pptx - PDF 123456
LEVEL 5   - SESSION 1 2023 (1).pptx - PDF 123456LEVEL 5   - SESSION 1 2023 (1).pptx - PDF 123456
LEVEL 5 - SESSION 1 2023 (1).pptx - PDF 123456KiaraTiradoMicha
 
BUS PASS MANGEMENT SYSTEM USING PHP.pptx
BUS PASS MANGEMENT SYSTEM USING PHP.pptxBUS PASS MANGEMENT SYSTEM USING PHP.pptx
BUS PASS MANGEMENT SYSTEM USING PHP.pptxalwaysnagaraju26
 
AI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
AI Mastery 201: Elevating Your Workflow with Advanced LLM TechniquesAI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
AI Mastery 201: Elevating Your Workflow with Advanced LLM TechniquesVictorSzoltysek
 
Chinsurah Escorts ☎️8617697112 Starting From 5K to 15K High Profile Escorts ...
Chinsurah Escorts ☎️8617697112  Starting From 5K to 15K High Profile Escorts ...Chinsurah Escorts ☎️8617697112  Starting From 5K to 15K High Profile Escorts ...
Chinsurah Escorts ☎️8617697112 Starting From 5K to 15K High Profile Escorts ...Nitya salvi
 
Software Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsSoftware Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsArshad QA
 

Dernier (20)

8257 interfacing 2 in microprocessor for btech students
8257 interfacing 2 in microprocessor for btech students8257 interfacing 2 in microprocessor for btech students
8257 interfacing 2 in microprocessor for btech students
 
Introducing Microsoft’s new Enterprise Work Management (EWM) Solution
Introducing Microsoft’s new Enterprise Work Management (EWM) SolutionIntroducing Microsoft’s new Enterprise Work Management (EWM) Solution
Introducing Microsoft’s new Enterprise Work Management (EWM) Solution
 
How To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected WorkerHow To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected Worker
 
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
 
Pharm-D Biostatistics and Research methodology
Pharm-D Biostatistics and Research methodologyPharm-D Biostatistics and Research methodology
Pharm-D Biostatistics and Research methodology
 
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsUnveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
 
Exploring the Best Video Editing App.pdf
Exploring the Best Video Editing App.pdfExploring the Best Video Editing App.pdf
Exploring the Best Video Editing App.pdf
 
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
 
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
 
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfLearn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
 
TECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providerTECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service provider
 
Right Money Management App For Your Financial Goals
Right Money Management App For Your Financial GoalsRight Money Management App For Your Financial Goals
Right Money Management App For Your Financial Goals
 
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
 
ManageIQ - Sprint 236 Review - Slide Deck
ManageIQ - Sprint 236 Review - Slide DeckManageIQ - Sprint 236 Review - Slide Deck
ManageIQ - Sprint 236 Review - Slide Deck
 
The Guide to Integrating Generative AI into Unified Continuous Testing Platfo...
The Guide to Integrating Generative AI into Unified Continuous Testing Platfo...The Guide to Integrating Generative AI into Unified Continuous Testing Platfo...
The Guide to Integrating Generative AI into Unified Continuous Testing Platfo...
 
LEVEL 5 - SESSION 1 2023 (1).pptx - PDF 123456
LEVEL 5   - SESSION 1 2023 (1).pptx - PDF 123456LEVEL 5   - SESSION 1 2023 (1).pptx - PDF 123456
LEVEL 5 - SESSION 1 2023 (1).pptx - PDF 123456
 
BUS PASS MANGEMENT SYSTEM USING PHP.pptx
BUS PASS MANGEMENT SYSTEM USING PHP.pptxBUS PASS MANGEMENT SYSTEM USING PHP.pptx
BUS PASS MANGEMENT SYSTEM USING PHP.pptx
 
AI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
AI Mastery 201: Elevating Your Workflow with Advanced LLM TechniquesAI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
AI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
 
Chinsurah Escorts ☎️8617697112 Starting From 5K to 15K High Profile Escorts ...
Chinsurah Escorts ☎️8617697112  Starting From 5K to 15K High Profile Escorts ...Chinsurah Escorts ☎️8617697112  Starting From 5K to 15K High Profile Escorts ...
Chinsurah Escorts ☎️8617697112 Starting From 5K to 15K High Profile Escorts ...
 
Software Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsSoftware Quality Assurance Interview Questions
Software Quality Assurance Interview Questions
 

Tips and Tricks of Developing .NET Application

  • 1. Tips and Tricks of Developing .NET Application Joni Applied Technology Laboratories Bina Nusantara University
  • 2. Agenda  General Best Practices  ASP .NET Specific  Windows Forms Specific  Resources
  • 3. General Best Practices  Looping optimization ArrayList list = new ArrayList();ArrayList list = new ArrayList(); for(int ifor(int i == 0; i0; i << list.Count; i++)list.Count; i++) {{ MyObject o = (MyObject)list[i];MyObject o = (MyObject)list[i]; o.DoSomeWork();o.DoSomeWork(); }} ArrayList list = new ArrayList();ArrayList list = new ArrayList(); MyObject oMyObject o = null;= null; for(int ifor(int i == 00, n =, n = list.Count; ilist.Count; i << nn; i++); i++) {{ o = (MyObject)list[i];o = (MyObject)list[i]; o.DoSomeWork();o.DoSomeWork(); }}
  • 4. General Best Practices  Use proper casting, avoid polymorphic call String s = “Hello world”;String s = “Hello world”; Session[“key”] = s;Session[“key”] = s; …… String result = Session[“key”].ToString();String result = Session[“key”].ToString(); String s = “Hello world”;String s = “Hello world”; Session[“key”] = s;Session[“key”] = s; …… String result =String result = (string)(string)Session[“key”];Session[“key”];
  • 5. General Best Practices  Acquire, Execute, Release pattern  Works with any IDisposable object  Data access classes, streams, text readers and writers, network classes, etc. using (Resource res = new Resource()) {using (Resource res = new Resource()) { res.DoWork();res.DoWork(); }} Resource res = new Resource(...);Resource res = new Resource(...); try {try { res.DoWork();res.DoWork(); }} finally {finally { if (res != null) ((IDisposable)res).Dispose();if (res != null) ((IDisposable)res).Dispose(); }}
  • 6. General Best Practices static void Copy(string sourceName, string destName) {static void Copy(string sourceName, string destName) { Stream input = File.OpenRead(sourceName);Stream input = File.OpenRead(sourceName); Stream output = File.Create(destName);Stream output = File.Create(destName); byte[] b = new byte[65536];byte[] b = new byte[65536]; int n;int n; while ((n = input.Read(b, 0, b.Length)) != 0) {while ((n = input.Read(b, 0, b.Length)) != 0) { output.Write(b, 0, n);output.Write(b, 0, n); }} output.Close();output.Close(); input.Close();input.Close(); }} static void Copy(string sourceName, string destName) {static void Copy(string sourceName, string destName) { Stream input = File.OpenRead(sourceName);Stream input = File.OpenRead(sourceName); try {try { Stream output = File.Create(destName);Stream output = File.Create(destName); try {try { byte[] b = new byte[65536];byte[] b = new byte[65536]; int n;int n; while ((n = input.Read(b, 0, b.Length)) != 0) {while ((n = input.Read(b, 0, b.Length)) != 0) { output.Write(b, 0, n);output.Write(b, 0, n); }} }} finally {finally { output.Close();output.Close(); }} }} finally {finally { input.Close();input.Close(); }} }} static void Copy(string sourceName, string destName) {static void Copy(string sourceName, string destName) { using (Stream input = File.OpenRead(sourceName))using (Stream input = File.OpenRead(sourceName)) using (Stream output = File.Create(destName)) {using (Stream output = File.Create(destName)) { byte[] b = new byte[65536];byte[] b = new byte[65536]; int n;int n; while ((n = input.Read(b, 0, b.Length)) != 0) {while ((n = input.Read(b, 0, b.Length)) != 0) { output.Write(b, 0, n);output.Write(b, 0, n); }} }} }}
  • 7.  In time critical application, avoid using ‘foreach’ General Best Practices public static void Main(string[] args) {public static void Main(string[] args) { foreach (string s in args) Console.WriteLine(s);foreach (string s in args) Console.WriteLine(s); }} public static void Main(string[] args) {public static void Main(string[] args) { for(int i = 0, n = args.Length; i < n; i++)for(int i = 0, n = args.Length; i < n; i++) Console.WriteLine(args[i]);Console.WriteLine(args[i]); }}
  • 8. General Best Practices public ArrayList GetList()public ArrayList GetList() {{ ArrayList temp = new ArrayList();ArrayList temp = new ArrayList(); …… return temp;return temp; }} …… public void DoWpublic void DoWoork()rk() {{ ArrayList list = new ArrayList();ArrayList list = new ArrayList(); list = GetList();list = GetList(); }}  Avoid unnecessary object instantiation public ArrayList GetList()public ArrayList GetList() {{ ArrayList temp = new ArrayList();ArrayList temp = new ArrayList(); …… return temp;return temp; }} …… public void DoWork()public void DoWork() {{ ArrayList list =ArrayList list = nullnull;; list = GetList();list = GetList(); }} public ArrayList GetList()public ArrayList GetList() {{ ArrayList temp = new ArrayList();ArrayList temp = new ArrayList(); …… return temp;return temp; }} …… public void DoWork()public void DoWork() {{ ArrayList list =ArrayList list = GetList()GetList();; }}
  • 9. General Best Practices  Use StringBuilder for string manipulation publicpublic stringstring ProcessLongText()ProcessLongText() {{ string text = “How are you?”;string text = “How are you?”; string s = text;string s = text; for(int i = 0; i < 1000; i++)for(int i = 0; i < 1000; i++) {{ s += text;s += text; }} return s;return s; }} public string ProcessLongText()public string ProcessLongText() {{ string text = “How are you?”;string text = “How are you?”; StringBuilder s = new StringBuilder(text);StringBuilder s = new StringBuilder(text); for(int i = 0; i < 1000; i++)for(int i = 0; i < 1000; i++) {{ s.Append(text);s.Append(text); }} return s.ToString();return s.ToString(); }}
  • 10. General Best Practices  Do not rely on exceptions in your code try {try { result = 100 / num;result = 100 / num; }} catch (Exception e) {catch (Exception e) { result = 0;result = 0; }} if (num != 0)if (num != 0) result = 100 / num;result = 100 / num; elseelse result = 0;result = 0;
  • 11. General Best Practices  Don’t reinvent the wheel, unless you are super programmer, use existing class library  Use Data Access Application Block for accessing database objectobject resultresult == SqlHelper.ExecuteScalar(connectionString,SqlHelper.ExecuteScalar(connectionString, CommandType.StoredProcedure, spName, sqlParameters);CommandType.StoredProcedure, spName, sqlParameters);
  • 12. ASP .NET Specific  Disable ViewState if not used  Use output cache to speed-up performance  Disable SessionState if not used  Avoid unnecessary round trips to the server  Use Page.IsPostBack to avoid performing unnecessary processing on a round trip  Consider disabling AutoEventWireup for your application <%@ OutputCache Duration=“60" VaryByParam="None" Shared="true" %><%@ OutputCache Duration=“60" VaryByParam="None" Shared="true" %> <page enableSessionState="true|false|ReadOnly” /><page enableSessionState="true|false|ReadOnly” />
  • 13. ASP .NET Specific  Be sure to disable debug mode  Avoid using DataBinder.Eval <%# DataBinder.Eval(Container.DataItem, “myfield") %><%# DataBinder.Eval(Container.DataItem, “myfield") %> <%#<%# ((DataRowView)Container.DataItem)[“myfield”].ToString()((DataRowView)Container.DataItem)[“myfield”].ToString() %>%> <compilation defaultLanguage="c#"<compilation defaultLanguage="c#" debug=“debug=“falsefalse"" />/>
  • 14. ASP .NET Specific  Override method, instead of attaching delegate to it private void InitializeComponent()private void InitializeComponent() {{ this.Load += new System.EventHandler(this.Page_Load);this.Load += new System.EventHandler(this.Page_Load); }} private void Page_Load(object sender, System.EventArgs e)private void Page_Load(object sender, System.EventArgs e) {{ …… }} protectedprotected overrideoverride voidvoid OnOnLoad(System.EventArgs e)Load(System.EventArgs e) {{ …… }}
  • 15. ASP .NET Specific  Use IDataReader instead of DataSet  Use Repeater instead of DataGrid (if possible)  Use the HttpServerUtility.Transfer method to redirect between pages in the same application  Use early binding in Visual Basic .NET or JScript code <%@ Page Language="VB" Strict="true" %><%@ Page Language="VB" Strict="true" %>
  • 16. Windows Forms Specific  Use multithreading appropriately to make your application more responsive  Windows Forms uses the single-threaded apartment (STA) model because Windows Forms is based on native Win32 windows that are inherently apartment- threaded. The STA model requires that any methods on a control that need to be called from outside the control's creation thread must be marshaled to (executed on) the control's creation thread
  • 17. Windows Forms Specific if(this.InvokeRequired)if(this.InvokeRequired) {{ this.Invoke(this.Invoke( newnew EventHandler(this.DisableButton),EventHandler(this.DisableButton), new object[] {new object[] { null, EventArgs.Emptynull, EventArgs.Empty }} );); }}