posted by 네코냥이 2013. 8. 20. 09:25



http://www.c-sharpcorner.com/UploadFile/mahesh/what-is-new-in-C-Sharp-6-0/



posted by 네코냥이 2013. 7. 24. 14:16


Recently, I got a question in an email asking how to load an XML file and display it on the system console.

We can use XmlDocument to read an XML document. The Load method is used to load an XML into an XmlDocument. Once a document is loaded, we can use the Save method to display its content to the console. The key is, passing Console.Out as a parameter.

XmlDocument xmlDoc = new XmlDocument();

string filename = @"C:\Books\Books.xml";           

xmlDoc.Load(filename);

xmlDoc.Save(Console.Out);

You must import the System.Xml namespace in your code. 



posted by 네코냥이 2013. 6. 26. 14:26


Although DataContext/ObjectContext implement IDisposable, you can (in general)

get away without disposing instances. Disposing forces the context’s connection

to dispose—but this is usually unnecessary because L2S and EF close connections

automatically whenever you finish retrieving results from a query.

Disposing a context can actually be problematic because of lazy evaluation. Con-

sider the following:

IQueryable<Customer> GetCustomers (string prefix)

{

  using (var dc = new NutshellContext ("connection string"))

    return dc.GetTable<Customer>()

             .Where (c => c.Name.StartsWith (prefix));

}

...

foreach (Customer c in GetCustomers ("a"))

  Console.WriteLine (c.Name);

This will fail because the query is evaluated when we enumerate it—which is

after disposing its DataContext.

There are some caveats, though, on not disposing contexts:


• It relies on the connection object releasing all unmanaged resources on the

Close method. While this holds true with SqlConnection, it’s theoretically

possible for a third-party connection to keep resources open if you call

Close but not Dispose (though this would arguably violate the contract de-

fined by IDbConnection.Close).


• If you manually call GetEnumerator on a query (instead of using foreach) and

then fail to either dispose the enumerator or consume the sequence, the con-

nection will remain open. Disposing the DataContext/ObjectContext provides

a backup in such scenarios.


• Some people feel that it’s tidier to dispose contexts (and all objects that im-

plement IDisposable).

If you want to explicitly dispose contexts, you must pass a DataContext/Object

Context instance into methods such as  GetCustomers to avoid the problem

described.

posted by 네코냥이 2013. 6. 18. 14:09


요즘 활용하려고 하는 데이터베이스 형태.


열라 쉽다. 다만 셋팅에서 아직 곤혹을 느끼고 있다.



ADO.NET Entity Data Model.pdf



Entity Data 글자대로 봐서는,

관련 테이블마다 따로따로 사용하길 바라는 목적에서 만든 것 같다.


posted by 네코냥이 2013. 6. 12. 15:28

원본: http://www.c-sharpcorner.com/UploadFile/rmcochran/functional-programming-in-C-Sharp-currying/



Currying a method call breaks the single method into a chain of methods. Let's start with the a very simple method transformation as an example of what we will be doing.  If we have a method defined with one input and one output as follows:


Func<Int32Int32SubtractOne = x => x - 1;



We can call this normally as

SubtractOne(8);



If the method was tranformed to return a delegate with a single input parameter, we would be able to call it a bit differently

SubtractOne.Curry()(8)



How do we build our simplified Curry() method transformation?  It's very simple utility method that we can use to modify any type of function with one argument that will return a delegate:

public static Func<TInput1, TOutput> Curry<TInput1, TOutput>(this Func<TInput1, TOutput> f)
{
    return x => f(x);
}



Pretty simple concept... right?  In reality, we probably wouldn't really curry a function with only one input parameter because the whole point is to get the arguments down to one tastey argument per delegate "call", but hopefully this sample helps you understand how we will begin to spice up our methods with curry.

Ultimately we would like to be able to curry a method with multiple input parameters as follows:


Func<Int32Int32Int32Int32Int32>
    Add = (w, x, y, z) => w + x + y + z;

Console
.WriteLine(Add(1, 2, 3, 4));             // 
Normal call
Console
.WriteLine(Add.Curry()(1)(2)(3)(4));     // Curried Call



And we just need a library of utility methods that curry (and uncurry) multi-argument methods.  All the samples are in the code accompanying this article, but here is the Curry() method for the 4-argument input method.  At first, it's kind of painful to look at, but if you look at the other Curry() methods in the accompanying code.. itshould be pretty much self-explanatory. On the "outer shell" we have a delegate that takes a single input and returns another delegate (which takes a single input and returns another delegate... (and so on... and so on...)). So as a result we esentially have 4 "nested" delegates.


public static Func<TInput1, Func<TInput2, Func<TInput3, Func<TInput4, TOutput>>>> 
    Curry<TInput1, TInput2, TInput3, TInput4, TOutput>
    (
       this
 Func<TInput1, TInput2, TInput3, TInput4, TOutput> f
    )
{
    return w => x => y => z => f(w, x, y, z);
}



Now for the big question "Why the heck would you want to do that?". 

Using this currying technique gives us a different syntax more conducive to building up a library of complex composite functions from simpler functions.  For a (very(very)) simple example... if we wanted a function that computed the cubic area of a box, we could construct it from a simpler "Multiply" function as follows:


    Func<Int32Int32Int32> Multiply = (x, y) => x * y;

    Func<Int32Int32Int32Int32>
        CubicArea = (length, width, height) => Multiply.Curry()(Multiply(length, width))(height);

    Console.WriteLine("The cubic area is: " + CubicArea(2, 3, 4).ToString());



We could also use currying to reduce the number of input parameters.  For example, if we wanted to find the cubic area of a perfectly square cube we could use currying to combine the input parameters.


Func<Int32Int32>
    PerfectCubeArea = (length) => Multiply.Curry()(Multiply(length, length))(length);

As you can see, currying is really nothing more than a different syntax for calling our already existing methods.  However, this powerful technique becomes more and more useful when we get into complex computations and want to build functionality from a composite tree perspective.

I hope you enjoy currying up your C# methods (which are especially tastey with coconut milk and shrimp).

Until next time,
Happy coding



posted by 네코냥이 2013. 6. 9. 17:45
-

Can you call Directory.GetFiles() with multiple filters?

-

I am trying to use the Directory.GetFiles() method to retrieve a list of files of multiple types, such as mp3's and jpg's. I have tried both of the following with no luck:

Directory.GetFiles("C:\\path", "*.mp3|*.jpg", SearchOption.AllDirectories);
Directory.GetFiles("C:\\path", "*.mp3;*.jpg", SearchOption.AllDirectories);

Is there a way to do this in one call?

-
up vote105down voteaccepted
var files = Directory.GetFiles("C:\\path", "*.*", SearchOption.AllDirectories)
            .Where(s => s.EndsWith(".mp3") || s.EndsWith(".jpg"));

edit: Please read the comments. The improvement that Paul Farry suggests, and the memory/performance issue that Christian.K points out are both very important.

share|improve this answer
4 
Man, I have to think in terms of LINQ more often. Nice solution! – Ken Pespisa Sep 23 '09 at 2:29
18 
Just make sure that you understand the implications though: this will return all files in a string array and then filter that by the extensions you specify. That might not be a big issue if "C:\Path" doesn't have lot of files underneath it, but may be a memory/performance issue on "C:\" or something like that. – Christian.K Feb 14 '10 at 12:13
10 
... 2 years later: Nice code, but watch out with this, if you have a file that ends with .JPG it won't make it. Better adds.ToLower().Endswith... – Stormenet May 5 '10 at 9:35
31 
you could just use s.EndsWith(".mp3", StringComparison.OrdinalIgnoreCase) – Paul Farry May 31 '10 at 22:58
32 
Note that with .NET 4.0, you can replace Directory.GetFiles with Directory.EnumerateFiles,msdn.microsoft.com/en-us/library/dd383571.aspx , which will avoid the memory issues that @Christian.K mentions. – Jim Mischel Dec 2 '11 at 22:58
---------------------------------------------------------------------------------------------

How about this:

private static string[] GetFiles(string sourceFolder, string filters, System.IO.SearchOption searchOption)
{
   return filters.Split('|').SelectMany(filter => System.IO.Directory.GetFiles(sourceFolder, filter, searchOption)).ToArray();
}

I found it here (in the comments): http://msdn.microsoft.com/en-us/library/wz42302f.aspx 

share|improve this answer
I'm guessing this avoids the potential memory pitfalls of the top rated answer? In which case, it should be rated higher! – Dan W Feb 1 at 18:48
It helped me. Thank you! – Maxim Eliseev Feb 6 at 13:31
1 
@DanW The top rated answer surely puts burden on the memory but I think that shouldn't be such a problem. I liked this answer too, but it's actually (much) slower then the accepted answer. Check this SpeedTest  – OttO Feb 13 at 22:37
Thanks. Glad to see it's only about twice as slow - I'll stick with it for the meantime I think. – Dan W Feb 17 at 19:47
-
-




posted by 네코냥이 2013. 5. 11. 20:00

ADO.NET + ASP.NET DB 연동 간단한 예제  ADO.NET 

2012/03/09 11:47

복사http://cepiloth.blog.me/70133307765


서버는 IIS

DBMS 는 MSSQL

 

 

ASP.NET 웹페이지에서 ADO.NET 를 사용하여

데이타 베이스를 연결하는 간단한 예제

 

 

using System.Data;
using System.Data.SqlClient; //SQL 서버 데이터를 사용할 때

 

 

using System.Data;
using System.Data.OleDB; // OLeDb 데이터를 사용할때

 

 

show page (aspx, asp)

 

 protected void Page_Load(object sender, EventArgs e)
    {
        string source = @"Server=localhost;uid=sa;pwd=1234;database=student";

        //1. db connect
        SqlConnection conn = new SqlConnection(source);
        conn.Open();

        //2. instruction 
        String sql = "SELECT * FROM IMAGES";
        SqlCommand cmd = new SqlCommand(sql, conn);

        //3. instruction exe
        SqlDataReader reader = cmd.ExecuteReader();

        //4. show pages

        Response.Write("<table border=1>");

        while (reader.Read())
        {
            Response.Write("<tr>");

            for (int i = 0; i<reader.FieldCount; i++)
            {
                Response.Write("<td>"+reader[i]+"</td>");
            }
            Response.Write("</tr>");
        }

        Response.Write("</table>");

        // 5. db close
        reader.Close();
        conn.Close();
    }

posted by 네코냥이 2013. 3. 18. 14:23


VS2010_VisualCshap_shortcut.pdf


posted by 네코냥이 2013. 2. 3. 15:01

 일단, 제가 C#을 배우게 된 이유가 

.NET 기반의 웹프로그래밍이기 떄문에 시야가 좁음을 고려해주시길 바랍니다.


C# 관련 커뮤니티

- 훈스닷넷        http://www.hoons.kr/

- 태요닷넷        http://www.taeyo.pe.kr/default.aspx

- C# 코너         http://www.c-sharpcorner.com  

(해외싸이트. 최신정보를 아주쉽게 설명해줌. 자료방대)


- 개발 관련 정보를 얻는데, 커뮤니티는 정말 필수적인 곳입니다. 

모르는 정보를 무료로 답변받을 수 있는 곳이니까요.


C# 라이브러리 싸이트

- http://msdn.microsoft.com/en-us/library/aa645596(VS.71).aspx