You might check out e.g.

[link:msdn.microsoft.com]

[link:msdn.microsoft.com]

They do not yet have code samples for F#, but the same APIs are used by both F# and C#, so the C# examples are telling. If you need more detailed help (or need help translating to F#), post a followup question.

By on 10/19/2009 1:17 PM ()

I don't understand how to cast this code in C# to F#?

By on 10/19/2009 1:43 PM ()

I translated it:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
 

#if READ

(*
C#: <A href="http://msdn.microsoft.com/en-us/library/db5x7c0d.aspx">http://msdn.microsoft.com/en-us/library/db5x7c0d.aspx</A>
using System;
using System.IO;
public class TextFromFile 
{
    private const string FILE_NAME = "MyFile.txt";
    public static void Main(String[] args) 
    {
        if (!File.Exists(FILE_NAME)) 
        {
            Console.WriteLine("{0} does not exist.", FILE_NAME);
            return;
        }
        using (StreamReader sr = File.OpenText(FILE_NAME))
        {
            String input;
            while ((input=sr.ReadLine())!=null) 
            {
                Console.WriteLine(input);
            }
            Console.WriteLine ("The end of the stream has been reached.");
        }
    }
}
*)

open System
open System.IO
let FILE_NAME = "MyFile.txt"
let Main() =
    if not(File.Exists(FILE_NAME)) then
        Console.WriteLine("{0} does not exist.", FILE_NAME)
    use sr = File.OpenText(FILE_NAME)
    let mutable input = sr.ReadLine()
    while (input <> null) do
        Console.WriteLine(input)
        input <- sr.ReadLine()
    Console.WriteLine ("The end of the stream has been reached.")
Main()

#else
(*
C#: <A href="http://msdn.microsoft.com/en-us/library/6ka1wd3w.aspx">http://msdn.microsoft.com/en-us/library/6ka1wd3w.aspx</A>
using System;
using System.IO;
public class TextToFile 
{
    private const string FILE_NAME = "MyFile.txt";
    public static void Main(String[] args) 
    {
        if (File.Exists(FILE_NAME)) 
        {
            Console.WriteLine("{0} already exists.", FILE_NAME);
            return;
        }
        using (StreamWriter sw = File.CreateText(FILE_NAME))
        {
            sw.WriteLine ("This is my file.");
            sw.WriteLine ("I can write ints {0} or floats {1}, and so on.", 
                1, 4.2);
            sw.Close();
        }
    }
}
*)

open System
open System.IO
let FILE_NAME = "MyFile.txt"
let Main() =
    if File.Exists(FILE_NAME) then
        Console.WriteLine("{0} already exists.", FILE_NAME)
    else
        use sw = File.CreateText(FILE_NAME)
        sw.WriteLine ("This is my file.")
        sw.WriteLine ("I can write ints {0} or floats {1}, and so on.",
            1, 4.2)
        sw.Close()
Main()

#endif
By on 10/19/2009 2:17 PM ()

wow..thank you very much it was very helpful..probably I will have more question..so if you can answer I will be glad..

By on 10/19/2009 3:07 PM ()
IntelliFactory Offices Copyright (c) 2011-2012 IntelliFactory. All rights reserved.
Home | Products | Consulting | Trainings | Blogs | Jobs | Contact Us | Terms of Use | Privacy Policy | Cookie Policy
Built with WebSharper