What is the equivalent of this JavaScript code in c#? [closed] - c#

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 10 years ago.
I have this JavaScript file that I need to write in C#. I've done many but stuck on it.
Could some body help me with this?
var biginteger=new bigint(convert);
var mod = bigint_mod(biginteger, new bigint(97));
var y = bigint_number(mod);
I am unable to interpret these JavaScript functions.

using System.Numerics;
BigInteger dividend= new BigInteger(1222222);
BigInteger mod;
BigInteger.DivRem(dividend, new BigInteger(97), out mod);
//mod will have the result
Or
BigInteger dividend = BigInteger.Parse("3243434343434434");
BigInteger divisor = BigInteger.Parse("97");
BigInteger mod;
BigInteger.DivRem(dividend,divisor, out mod);

First you need a reference to the assembly System.Numerics.dll which is part of the BCL since 2010 (.NET 4.0 and later).
The use something like:
using System.Numerics
...
var bigInteger = (BigInteger)convert; // or BigInteger.Parse(convert); not sure what type convert is
var y = bigInteger % 97;
Surely, the BigInteger struct overloads the % operator. And the literal 97 will be implicitly converted to a BigInteger.
If you don't need a new variable, you can also say: bigInteger %= 97;.

Related

C# reset many integer variables quicker [closed]

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 10 years ago.
Is there a way to reset these variables quicker like at the time of declaration?
Declaration:
int numa1, numa2, numa3, numd1, numd2, numd3;
Reset afterwards:
numa1 = 0;
.
.
.
numd3 = 0;
Because I will change these variables, but then I need to reset them as 0, OK?
Replying the comments below:
Sorry, I didn't change "Reset afterward" to "Initializes afterward". Someone else did that.
Sorry, but you cannot change the values of the variables like:
numa1, numa2, numa3, numd1, numd2, numd3 = 0;
I tried and I received Error 1, 2, 4.
By quicker if you mean faster, I donot think there is any better alternative.
If you mean reducing some lines,
You can choose either
int numa1=0, numa2=0, numa3=0, numd1=0, numd2=0, numd3 = 0;
or
int numa1, numa2, numa3, numd1, numd2, numd3 = 0;
numa1= numa2= numa3= numd1= numd2= numd3;
I guess that you should have used two arrays, I never had a function that used so many variables with such names (sequential numbers).
If you'd use arrays, Your code will look like this :
int[] numa = new [] {0,0,0,0};
int[] numd = new [] {0,0,0,0};
But this is up to you.
For more information about arrays

How to round up the number in c# [closed]

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 10 years ago.
How can I round up values like this:
1.001 => 2
3.3 => 4
Means if the number has fractional part than i want the smallest integer number greater than the number ?
I used Math.Ceiling() but is not helping. How can i do this ?
Math.Ceiling will work. can you tell what its not working ? in term of any errors or returned result.
var returnVal=Math.Ceiling(yourValue);
Use Math.Ceiling() method.
Returns the smallest integer greater than or equal to the specified
number.
var i = Math.Ceiling(1.001);
var j = Math.Ceiling(3.3);
Console.WriteLine(i);
Console.WriteLine(j);
Output:
2
4
Math.Ceiling(value);
Should work.
double x;
x = Math.Ceiling(5.2) ;//Result; 6
x = Math.Ceiling(5.7) ;//Result; 6
x = Math.Ceiling(-5.2) ;//Result;-5
x = Math.Ceiling(-5.7) ;//Result;-5
This is a simple example. How can't you use it? Maybe you miss to assign a variable to
Math.Ceiling();

Convert int(round(time.time())) to C# [closed]

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 10 years ago.
I am trying to convert this python instruction to C#
int(round(time.time()))
But I cannot figure out what it does exactly.
You need to use UtcNow as opposed to Now or else you will get an answer offset by your timezone.
TimeSpan t = (DateTime.UtcNow - new DateTime(1970, 1, 1));
int timestamp = (int) t.TotalSeconds;
time.time() will return the current time as a float which represents seconds since 1/1/1970, round() will round that float to the nearest integer value, and int() will convert the value to the integer type.
For example:
>>> time.time()
1351702579.645324
>>> round(time.time())
1351702580.0
>>> int(round(time.time()))
1351702580

Confused about '+=' operator in C# [closed]

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 11 years ago.
We were discussing something we saw in a coding class. From what we recall, the instructor instantiated/created a variable somehow using += and C#.
I know it wasn't dealing with subscribing to events or adding y to x but didn't know if anyone out there could shed some light on what we might have seen?
The += operator is overloaded for many types (as well as defined for built in types). Really it's hard to tell just from your blurb what he was using it to do.
Add to existing integer:
x += 10; // add 10 to existing value in x (x = x + 10)
Concatenate a string:
name += ", Jr"; // adds ", Jr" suffix to a string.
Subsribe to an event
myClass.OnSomeEvent += myEventHandler; // adds myEventHandler to mutlicast delegate
So basically, in a nutshell, it just adds the current value to the existing one. Without more information, can't be more specific...
May be you saw something like this
int x = 10;
x += 10 means x = x + 10

How to increment a integer variable itself [closed]

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 11 years ago.
How to increment a integer variable itself in C#?
i need something the variables as
integer1
integer2
integer3
integer4
integer5
In a for loop when it is looped i want the variables gets incremented. How can i get?
Dynamic identifier names are not possible in C# and any other .NET language.
You can use an array or generic list instead - these will hold a collection of your type and allow you to iterate over it.
var intArr = new int[5];
var intList = new List<int>(5);
foreach(var num in intList)
{
// do something with num
}
What you really want is an array:
var ints = new int[5]; // declares an array of five integers, ints[0] to ints[4]
for (int i = 0; i < 5; i++) {
// do something with ints[i]
}
For a more in-depth introduction, have a look at the following tutorial on MSDN. It's for an old C# version, but the concepts still apply:
Arrays Tutorial
You can't change variable names dynamically in C#.

Categories

Resources