Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
Can somebody explain this code in detail.basically how it works?
Int32[] numbers = a.Split(',').Select(s => Int32.Parse(s)).ToArray();
Let's pretend
string a = "1,2,3,4,5,6,7";
Then
Int32[] numbers = a.Split(',').Select(s => Int32.Parse(s)).ToArray();
Will create an array named numbers that will contain the values 1,2,3,4,5,6,7.
Its converting a comma separated list of integers encoded as a string into an array of integers.
It takes a string consisting of comma separated integers and converts this string to an array of integers:
"1,2,3,4,5" -> {1, 2, 3, 4, 5}
Looks like it fills an array of 32 bits numbers with the results of the conversion of the elements contained in "a" to integers on 32 bits.
as an example : "1,2,3" would become an array like this : [1,2,3]
Related
Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 8 years ago.
Improve this question
I have a int array .
int[] numbers = new int[5] {1, 2, 3, 4, 5};
How can all the elements of this array displayed as a single number from last index to 0th index.In this case , it has to be 54321.
string result = string.Join("", numbers.Reverse());
Or even simpler:
string result = string.Concat(numbers.Reverse());
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 8 years ago.
Improve this question
i want to update a Global Array that contain 24 data
Decimal[] GolbalInfo = new Decimal[24];
with three different small array containing each one 8 data
Decimal[] TableSwInfo ;
how can i do it please ?
You can use CopyTo. Assuming you have arrays like the following:
//main destination array
Decimal[] GolbalInfo = new Decimal[24];
//smaller source arrays
Decimal[] SmallOne = new Decimal[8];
Decimal[] SmallTwo = new Decimal[8];
Decimal[] SmallThree = new Decimal[8];
You can set the large one using the smaller ones like this:
SmallOne.CopyTo(GolbalInfo, 0);//sets 0 - 7
SmallTwo.CopyTo(GolbalInfo, 7);//sets 8 - 15
SmallThree.CopyTo(GolbalInfo, 15);//sets 16 - 23
I would recommend that you validate the sizes before adding them, although it may be a safe assumption depending on your setup
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
Quick question.
I'm making a diagram so the numbers i'm passing to the function can be anything (depending on zoom and such). Lets say I want to round the number 3.086948353 to 3 but i still want other numbers like 2.199999999 to round to 2.2.
Currently it just looks like this:
Math.Round(value, 10)
You want to do two things in single shot:
Get the integer value if first digit after decimal is 0
Get the rounded value upto last 2 digits if its first digit after decimal is not 0.
For second option you can use:
newValue = Math.Round(value, 2)
Now comes the first requirement:
Once you get the decimal with 2 digits after decimal, get last two digits:
int decimalValue= (int)((newValue - (int)newValue ) * 100);
if(decimalValue < 10)
{
newValue = Math.Floor(value);
}
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
I was looking for RSACryptoServiceProvider helper and found two different implementations
1) http://www.cnblogs.com/WYB/archive/2008/06/19/1225704.html
2) https://github.com/robvolk/Helpers.Net/blob/master/Src/Helpers.Net/EncryptionExtensions.cs
both of them working
var encryptedBytes = myBytes.RSAEncrypt(publicKey);
System.Text.Encoding.Unicode.GetString(encryptedBytes);
returns strings like "蹩巷Ӂය馧㾵봽놶徤蕺蓷課Ϝ堲泍썳⁙䃑ക늏...."
myString.EncryptStringUsingXMLFile(publicKey)
returns strings like "AnvFFT6YpoiAyIFwl+tueZq56Zcb0B7WhBEvz5uWl...."
May be some one can explain why first one producing Chinese strings and how to change that?
What approach is better?
To answer your first question. While it may look like it is producing Chinese characters what is actually happening is it is turning a byte array into unicode. In c# typically when you want to store a byte array you convert it to base64 which is what your second example appears to return.
Your first example would become this:
var encryptedBytes = myBytes.RSAEncrypt(publicKey);
Convert.ToBase64String(encryptedBytes) // this line changed
returns strings like "AnvFFT6YKpoiAy...."
As for what is recommended, the most common is to use base64. The reasons people use base64 over unicode or UTF-8 for binary data can be found in these answers:
https://stackoverflow.com/a/201491/701062
MSDN - Convert.ToBase64String(byte[])
http://msdn.microsoft.com/en-us/library/dhx0d524(v=vs.100).aspx
MSDN - Convert.FromBase64String(string) - Useful if you need to convert back into a byte array
http://msdn.microsoft.com/en-us/library/system.convert.frombase64string(v=vs.100).aspx
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
User input a word eg( Hello ), how do I put hello into an array? such that
array[1]=h
array[2]=e
array[3]=l
array[4]=l
array[5]=o
Use the string method ToCharArray like this :
char[] input = "hello".ToCharArray();
If you have a lot of logic to do after, I'd recommend using a List instead, which you can get with :
List<char> input = "hello".ToList();
And as a side note, h will be in yourArray[0] (or .ElementAt(0)) not [1], since C# is 0-based; all indexes start at 0 instead of 1.
Actually you don't need to do anything special to accomplish this. You can already access the characters in the string by using an indexer, like this:
"Hello"[0] will return "H", "Hello"[1] will return "e" and so on.
Try this:
char myArray[] = "Hello".ToCharArray();
Try below instead
char [] array = "Hello".ToArray();
use this
string[] a=Console.ReadLine() // Get String From user
char[] myCharArray= a.ToCharArray();