目前分類:C# 技術文章 (22)

瀏覽方式: 標題列表 簡短摘要

<HTML Agility Pack(HAP) 介紹>

1.HTML Agility Pack:簡單好用的快速 HTML Parser


<如何找尋 XPath>

imagefish 發表在 痞客邦 留言(0) 人氣()

JSON.NET Sample

JSON deserialization with JSON.net


To help user to auto-convert json to c# data structure. 

json2csharp


download json.net lib and document.

json.net library



imagefish 發表在 痞客邦 留言(0) 人氣()

Step1:開啟一個專案(EX: console application)


Step2:如下圖操作(點選 Reference),選取 Add Web Service,會跳出一個視窗。該視窗是WCF設定視窗,不過我們需要用的是舊型的Web Service,所以點選左下角的按鈕(Advance)。

1bbb  


Step3: 繼續往舊版的Web Service設定前進(點選下方的按鈕)

2_bbb   

imagefish 發表在 痞客邦 留言(0) 人氣()

Tutorial

http://csharp.net-informations.com/excel/csharp-excel-tutorial.htm

 

The Simple method of use

http://www.dotblogs.com.tw/yc421206/archive/2009/01/11/6727.aspx

imagefish 發表在 痞客邦 留言(0) 人氣()

睡前翻書翻到的。然後上msdn發現...嘿嘿,竟然沒講。

http://msdn.microsoft.com/zh-tw/library/14akc2c7(v=vs.100).aspx

這有點難用程式碼寫出來,不過我覺得應該用個...一些圖表示,有空在畫好了。

 // 預備畫圖...

這個關鍵字簡單來說就跟pointer概念上是一樣的,但是.....在C#裡面,假設你是用Object的話,他本身在傳遞上就是Call by reference。

imagefish 發表在 痞客邦 留言(0) 人氣()

http://msdn.microsoft.com/en-us/library/dd264739.aspx

msdn的說明。

先講 Optional Arguments(可選參數)應用在Method(方法)上,這功能就是幫你預設好參數(Arguments)值,當有輸入值的時候就聽遵循輸入值的話 ; 當沒有輸入值的時候就直接把預測值塞入。 這東西可以用Overload的寫法實作,但是程式碼將會壟長很多..。

 

(程式碼實作比較:Optional Arguments vs overload 寫法)

imagefish 發表在 痞客邦 留言(0) 人氣()

當初是為了處理兩個Array / List 放在同一個For loop內一起使用,但是不想要改動到既有的程式碼而上網查的。(簡單來說本來功能都寫好了,但是我臨時發現忘記記錄一筆資料,但我List 的 Data struct都設計好了不想再更動他,所以想想有沒有比較偷懶的方法)

.Net 4.0推出這個東西其實還蠻不錯的.....雖然當下看會覺得這個Func真的是一點屁用都沒有,因為一般人不會那麼蠢把都要放到For loop中的資料拆成兩個Array。

不過站在這種奇妙的案例下這Func就蠻有用的...= =++

http://stackoverflow.com/questions/1955766/iterate-two-lists-or-arrays-with-one-foreach-statment-in-c-sharp

http://stackoverflow.com/questions/4450650/using-foreach-loop-to-iterate-through-two-lists

imagefish 發表在 痞客邦 留言(0) 人氣()

回家在整理。


http://stackoverflow.com/questions/5766573/in-c-what-is-the-best-way-to-compare-2-integer-lists-array


 

imagefish 發表在 痞客邦 留言(0) 人氣()

回家在看~

 

http://big5.webasp.net/article/15/14889.htm

http://msdn.microsoft.com/en-us/library/ff650316.aspx

http://blog.tenyi.com/2006/09/csingleton-class.html

imagefish 發表在 痞客邦 留言(0) 人氣()

// Main function


class MainFunc
{
static void Main(string[] args)

imagefish 發表在 痞客邦 留言(0) 人氣()

// Main function

class MainFunc
    {
        static void Main(string[] args)
        {
            string[] animals = new string[] { "Koala", "Spider", "Elephant" };
            wherepractice prac = new wherepractice();
            // get animals of StartName is "S"
            prac.detailWhere(animals);
            // get amimals of StartName is "E"
            prac.lambdaWhere(animals);
            // as above result, but different implement.
            prac.delegateImpleWhere(animals);
            Console.ReadLine();
            return;
        }
    }

// subClass

        public void detailWhere(string[] animals)
        {
            var q = from a in animals
                    where a.StartsWith("S")
                    select a;

            foreach (string s in q)
            {
                printString(s);
            }
        }
        public void lambdaWhere(string[] animals)
        {
            var q = animals.Where(a => a.StartsWith("E"));
            foreach (string s in q)
            {
                printString(s);
            }
        }
        public void delegateImpleWhere(string[] animals)
        {
            // To utilize "delegate" to implement lambda expression "Where".
            var q = animals.Where(
                delegate(string a){return a.StartsWith("E");}
                );
            foreach (string s in q)
            {
                printString(s);
            }
        }

imagefish 發表在 痞客邦 留言(0) 人氣()

This is a simple sample for Exit statement.

        static void Main(string[] args)
        {
            Program.correctGoto();
            Program.GotoInfiniteLoop();
            Program.falseGoto();
        }

         //This is a correct Goto statement method.
         static public void correctGoto()
        {
            for (int i = 0; i < 100; i++)
            {
                Console.WriteLine("{0}", i);
                if (i == 5)
                {
                    goto Exit;
                }
            }
            Exit: Console.WriteLine("Exit");
        }

        //If you put Exit tag before goto statement, it will cause infinite loop.p>
        static public void GotoInfiniteLoop()
        {
            Exit: Console.WriteLine("Exit");
            
            for (int i = 0; i < 100; i++)
            {
                Console.WriteLine("{0}", i);
                if (i == 7)
                {
                    goto Exit;
                }
            }
 
        }

         //It's a wrong method to use exit statement.
         static public void falseGoto()
        {
            for (int i = 0; i < 100; i++)
            {
                Console.WriteLine("{0}", i);
                if (i == 7)
                {
                    Exit: Console.WriteLine("Exit");
                }
                // this method can't jump from external into internal.
                goto Exit;
            }
        }

imagefish 發表在 痞客邦 留言(0) 人氣()

// Main function

class MainFunc
    {
        static void Main(string[] args)
        {
            string[] animals = new string[] { "Koala", "Spider", "Elephant" };
            wherepractice prac = new wherepractice();
            // get animals of StartName is "S"
            prac.detailWhere(animals);
            // get amimals of StartName is "E"
            prac.lambdaWhere(animals);
            // as above result, but different implement.
            prac.delegateImpleWhere(animals);
            Console.ReadLine();
            return;
        }
    }

// subClass

        public void detailWhere(string[] animals)
        {
            var q = from a in animals
                    where a.StartsWith("S")
                    select a;

            foreach (string s in q)
            {
                printString(s);
            }
        }
        public void lambdaWhere(string[] animals)
        {
            var q = animals.Where(a => a.StartsWith("E"));
            foreach (string s in q)
            {
                printString(s);
            }
        }
        public void delegateImpleWhere(string[] animals)
        {
            // To utilize "delegate" to implement lambda expression "Where".
            var q = animals.Where(
                delegate(string a){return a.StartsWith("E");}
                );
            foreach (string s in q)
            {
                printString(s);
            }
        }

imagefish 發表在 痞客邦 留言(0) 人氣()

class ListInit
    {
        static void Main(string[] args)
        {
            // The demo of List Initialize Set including old declaration and new declaration(C#3.0)
            // Old initialization.
            List stringOld = new List();
            stringOld.Add("string_1");
            stringOld.Add("string_2");

            // New initialization.
            List stringNew = new List()
            {
                "string_1",
                "string_2"
            };

            // Combine Object and List Init.
            List list = new List{
                new Contact{
                    LastName = "Alen",
                    DateOfBirth = new DateTime(1234,1,13)
                },
                new Contact{
                    LastName = "AlenTwo",
                    DateOfBirth = new DateTime(2345,1,23)
                }
            };
        }

        private class Contact
        {
            public string LastName { get; set; }
            public DateTime DateOfBirth { get; set; }
        }
    }

imagefish 發表在 痞客邦 留言(0) 人氣()

class Program
    {
        static void Main(string[] args)
        {
            // The demo of Object Initialize Set including old declaration and new declaration(C#3.0)
            
            // If member access modifier isn't declared as "public", method_1 and method_2 isn't working.
            // method_1
            Contact contact = new Contact();
            contact.LastName = "A-len";
            contact.DateOfBirth = new DateTime(2012, 04, 03);

            //method_2
            Contact contactNew = new Contact
            {
                LastName = "A-len",
                DateOfBirth = new DateTime(2012, 04, 03)
            };
        }

        private class Contact
        {
            public string LastName { get; set; }
            public DateTime DateOfBirth { get; set; }
        }
    }
 

imagefish 發表在 痞客邦 留言(0) 人氣()

StreamReader defaults to UTF-8 encoding unless specified otherwise, instead

of defaulting to the ANSI code page for the current system.

(Hint: Convert xls/xlsx file to csv file. the encoding is ANSI.)

http://msdn.microsoft.com/zh-tw/library/6aetdk20(v=vs.100).aspx


imagefish 發表在 痞客邦 留言(0) 人氣()

Main Function

namespace ConsoleGenericsAssumption
{
    class Program
    {
        static void Main(string[] args)
        {
            GenericTypeResolverTest v = new GenericTypeResolverTest("Hello Alam");
            //v.Value = "Hello ALam";
            v.ShowInConsole();
            // -----same result, differnet implementation---
            Console.WriteLine("-----same result, differnet implementation---");
            string showString = v.ToString();
            Console.WriteLine("{0}", showString);
            Console.ReadLine();

            // generic for string
            string ValueString = "Hello Yaya";
            ValueString.ShowInConsole();

            // generic for int
            int ValueInt = 12345;
            ValueInt.ShowInConsole();
        }
    }
}

 

Another class

    public class GenericTypeResolverTest
    {
        public string Value { get; set; }

        public GenericTypeResolverTest() { }
        public GenericTypeResolverTest(string value)
        {
            Value = value;
        }
        public override string ToString()
        {
            return Value.ToString();
        }
    }

    public static class GenericTypeResolverMethodTest
    {
        public static void ShowInConsole(this T obj)
        {
            Console.WriteLine(obj.ToString());
            Console.ReadLine();
        }
    }

imagefish 發表在 痞客邦 留言(0) 人氣()

static void Main(string[] args)
        {
            // [] is specific type and fixed length.
            // It is a data structure.
            String[] arr = new string[] {"Hi", "I", "am", "ALam"};
            ShowMessage(arr);

            // List is specific type and unbounded length. 
            // namespace is System.Collection.Generic
            List list = new List();
            list.Add("Hi");
            list.Add("I");
            list.Add("am");
            list.Add("Alam");
            ShowMessage(list);

            // ArrayList is any type and undounded length.
            // namespace is System.Collection
            ArrayList arraylist = new ArrayList();
            arraylist.Add("Hi");
            arraylist.Add("I");
            arraylist.Add("am");
            arraylist.Add("Alam");
            arraylist.Add(12345); // when we call the ShowMessage, it will be wrong.
            ShowMessage(arraylist);
        }

        private static void ShowMessage(string[] temp)
        {
            foreach (string aaa in temp)
            {
                Console.WriteLine("{0}", aaa);
            }
            Console.ReadLine();
        }

        private static void ShowMessage(List temp)
        {
            foreach (string aaa in temp)
            {
                Console.WriteLine("{0}", aaa);
            }
            Console.ReadLine();
            }

        private static void ShowMessage(ArrayList temp)
        {
            foreach (string aaa in temp)
            {
                Console.WriteLine("{0}", aaa);
            }
            Console.ReadLine();
        }
    }

imagefish 發表在 痞客邦 留言(0) 人氣()

// to associates a stored procedure which user defined in the database.
// Must write it before func.
[global::System.Data.Linq.Mapping.FunctionAttribute(Name ="stored procedure name")]
// Undertake on a code, we make a func. let user to access the stored procedure.
// When SP exist input variables, you must use "Linq.Mapping.ParameterAttribute" to 
// select the variable in DB and use "System.Nullable" to set 
// what variable you wnat to assign in code.
public int storedProcedureForC#Class(
[global::System.Data.Linq.Mapping.ParameterAttribute(Name:"inputVarName", 
DbType="inputVarType"] System.Nullable varInC#)
{
// Execute the stored procedure.
IExecuteResult objectForSP = this.ExecuteMethodCall(this, (
(MethodInfo)(MethodInfo.GetCurrentMethod())), varInC#);
return ((int)(result.ReturnValue));
}

imagefish 發表在 痞客邦 留言(0) 人氣()

So........We know "as" is a powerful method that perform certain types of conversions between compatible reference types. for example:

 

// ...... //
Array[] = dataTable;
// ....do something for dataTable.//
const string = "ALamTest";
Session[ALamTest] = dataTable;

//....do another something...//

Array[] getTable = Session[AlamTest] as Array[]

When we use Session Mechanism, "as" is a useful method let us to redesign the object which is taken out from the session.


imagefish 發表在 痞客邦 留言(0) 人氣()

1 2