Bonjour à tous, étant programmeur en Visual Basic.NET,
je me suis mis aujourd'hui au C#.

Malheureusement quand j'essaye de faire lire une configuration ( configuration.txt) ( enfin quand j'essaye de traduire mon Vb ), il me lance énormement d'erreur, même en ayant tout mis en bon C#.

Les méthodes Reader.ReadLine() ne sont pas compatible en String[].

Voici je vous donne le code en VB.NET en espérant que vous puissiez m'aider ...

Code : Sélectionner tout - Visualiser dans une fenêtre à part
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
Namespace Utils
    Public Class Config
 
        Private Shared _Items As New Dictionary(Of String, String)
 
        Public Shared Function GetItem(ByVal Item As String) As String
            If _Items.ContainsKey(Item) Then Return _Items(Item)
            MyConsole.Err("Can't find item '" & Item & "' in configuration file", True)
            Return ""
        End Function
 
        Public Shared Sub LoadConfig()
 
            If Not IO.File.Exists("realm.txt") Then
                MyConsole.Err("Can't find configuration file !", True)
            End If
 
            Try
 
                Dim Reader As New IO.StreamReader("realm.txt")
 
                While Not Reader.EndOfStream
 
                    Dim Line As String = Reader.ReadLine
 
                    If Line.Trim.StartsWith("#") Then Continue While
                    If Not Line.Contains("=") Then Continue While
 
                    Dim LigneInfos() As String = Line.Split("=".ToCharArray, 2)
 
                    Dim Item As String = LigneInfos(0).ToUpper.Trim
                    Dim Value As String = LigneInfos(1).Trim
 
                    If Item = "" Then Continue While
 
                    _Items.Add(Item, Value)
 
                End While
 
                UseConfig()
 
                MyConsole.Status("Configuration file loaded")
 
            Catch ex As Exception
 
                MyConsole.Err("Can't read configuration file !", True)
 
            End Try
 
        End Sub
 
        Private Shared Sub UseConfig()
 
           Config.DEBUG=GetItem("DEBUG")
 
        End Sub
 
    End Class
End Namespace