-8

I've got this code writted on VB.NET and I want to transform it to C#

I really dont know how to convert the MOD funciont without any error using %...

For f = 0 To 7
        For c = 0 To 7


            If (((c Mod 2) <> 0 AndAlso (f Mod 2) = 0) OrElse ((c Mod 2) = 0 AndAlso (f Mod 2) <> 0)) AndAlso f < 3 Then
                Dim fi As New BE.Ficha
                fi.Color = 1
                fi.Fila = f

                fi.Columna = c
                fi.Dama = False
                tab.Fichas.Add(fi)

            ElseIf (((c Mod 2) = 0 AndAlso (f Mod 2) <> 0) OrElse ((c Mod 2) <> 0 AndAlso (f Mod 2) = 0)) AndAlso f > 4
                Dim fi As New BE.Ficha
                fi.Color = -1
                fi.Fila = f

                fi.Columna = c
                fi.Dama = False
                tab.Fichas.Add(fi)

            End If


        Next

    Next
Flor Santoni
  • 33
  • 1
  • 5
  • 3
  • 6
    ... and what does your C# look like? – theGleep Feb 16 '18 at 20:23
  • Hi Flor, and welcome to Stack Overflow! Can you please include the error you are getting, the modification you want to make, and what you've tried so far to fix this? Also, if you could simplify your code to a minimum viable example, that would be great. Please include all this in your original question, **not** in the comments. Thanks! – Max von Hippel Feb 16 '18 at 20:23
  • c Mod 2 = 0 translates to `c % 2 == 0` – Mightee Feb 16 '18 at 20:24
  • 2
    Welcome to Stack Overflow. This is not a code translation service. Make an effort to do so yourself first; if you run into difficulties, you can explain the problem you've encountered, include the *relevant* portions of your code, and ask a specific question related to that code, and we'll try to help. If you can't get started at all, consider hiring a contractor to do the work for you. Good luck. – Ken White Feb 16 '18 at 20:24
  • 2
    `I really dont know how to...` The solution to that is not a StackOverflow post, but *research*. For instance **[% Operator (C# Reference)](https://learn.microsoft.com/en-us/dotnet/csharp/language-reference/operators/modulus-operator)** – Ňɏssa Pøngjǣrdenlarp Feb 16 '18 at 20:24
  • 1
    If you want to learn how to use MOD in C# then have a look at the link Plutonix has posted, if you just want to have exactly the same code in C# without understanding how it works then there are a number of online tools e.g. https://www.carlosag.net/tools/codetranslator/ – d219 Feb 16 '18 at 20:30
  • 2
    Unfortunately these kind of questions aren't going to go away anytime soon with all the people spoon-feeding answers to LQ-question ... – Manfred Radlwimmer Feb 16 '18 at 20:40
  • this is a pretty good converter - http://converter.telerik.com/ – Ctznkane525 Feb 16 '18 at 21:02

1 Answers1

-2

Check this code, I didn't have all of your code for testing it

    for (int f = 0; (f <= 7); f++)
    {
        for (int c = 0; (c <= 7); c++)
        {
            if ((((((c % 2) != 0) && ((f % 2) == 0)) || (((c % 2) == 0) && ((f % 2) != 0))) && (f < 3)))
            {
                BE.Ficha fi = new BE.Ficha();
                fi.Color = 1;
                fi.Fila = f;
                fi.Columna = c;
                fi.Dama = false;
                tab.Fichas.Add(fi);
            }
            else if ((((((c % 2) == 0) && ((f % 2) != 0)) || (((c % 2) != 0) && ((f % 2) == 0))) && (f > 4)))
            {
                BE.Ficha fi = new BE.Ficha();
                fi.Color = -1;
                fi.Fila = f;
                fi.Columna = c;
                fi.Dama = false;
                tab.Fichas.Add(fi);
            }

        }

    }
Egbert
  • 158
  • 4
  • 12
Ali Poustdouzan
  • 220
  • 2
  • 16
  • 6
    Pleased dont do Other peoples jobs – Mightee Feb 16 '18 at 20:51
  • 1
    @Mightee Sometimes people just need an example to understand how they convert their code and best way to do that is you find out what exactly your code should be in new language. Stop flame someone who need help and downvote their question, That's sad – Ali Poustdouzan Feb 17 '18 at 21:46