Converting split expression to C++ to C#

Asked

Viewed 130 times

0

I have the following condition in C++ and would like to move to C#. The problem I’m having is with the function div error:

The name 'div' does not exist in the Current context

if (quant > 0)
{
    return  div(quant, 7).quot;
}
  • 1

    What’s wrong with the div?

  • Put more information on the question and clarify your doubt and the problem. Cite examples of other attempts you made.

  • the div is underlined red with the following message: The name 'div' does not exist in the Current context

  • Because you need to use the div in C++? I provided an answer that gives you the same result in C#. Of course the problem could even be another. From the code section, not to determine this. If the problem is another, you can [Dit] your question to put the most complete code and information to help understand your problem.

  • @user2254936 Take a look at [tour]. You can accept an answer if it solved your problem. You can vote for all the posts on the site as well. Did any help you more? You need something to be improved?

1 answer

4

From what I understand you want to do a split and take only the quotient. If this is it I see no reason to use the function div not even on C++. The same goes for C#. Actually C# doesn’t even have a similar function ready (the advantage of this function is to return both the quotient and the rest) so you have an error trying to use it.

So in C# you just need to do a simple split with the division operator. Your code would look like this:

if (quant > 0)
{
    return  quant / 7;
}

I put in the Github for future reference.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.