Update Array and preserve data [closed] - c#

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

Related

Print Duplicate Items using LINQ [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Closed 9 years ago.
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
Questions concerning problems with code you've written must describe the specific problem — and include valid code to reproduce it — in the question itself. See SSCCE.org for guidance.
Improve this question
I want to print duplicate items using LINQ.
e.g. I want to print 1 at 10 times.
Here 1 is a string and 10 (Dynamic Number) is the number of times I want to print this string.
How can I do this?
You can use this constructor overload:
int count = 10;
string s = new String('1', count);
If you really wanted to use Linq, you could use Enumerable.Repeat:
int copies = 10;
foreach(var s in Enumerable.Repeat("1", copies))
{
Console.WriteLine(s);
}
But for that matter, a simple for-loop would work too:
int copies = 10;
for(int i = 0; i < copies; i++)
{
Console.WriteLine("1");
}

how to use StreamReader in C# to read only entries over a specific length to a list? [closed]

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
when using StreamReader in C# to load a txt file into a list, i assume that using a simple "If" the string's length is over a particular length, it will add it to the list. can anyone provide C# code for this? this IS homework, but it's NOT a C# class. the instructor would gladly provide this if i asked this specifically. thx.
the txt file is a dictionary of ~280,000 words, one per line. very simple move to turn into a list, but i'm wondering about getting words at least 2 characters long.
Just use LINQ to give you a subset.
List<string> lines = File.ReadLines(filename)
.Where(l => l.Length > specifiedWordLength)
.ToList();

How to display a string variable in a specific number format like "#,0.##" [closed]

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 have a typed dataset with a column called price, which is of string datatype. And I'm showing this via ultrgrid/datagrid
How can I show the price in number format.
For example: price ==123456
in the grid it should be like 12,354,56
Try this
var a = price.ToString("##,###,##");
Reference
Custom Numeric Format Strings!
Look at some of the related links to the right of the screen. Some of them even ask the same question as you !

Cannot understand the following code? [closed]

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]

Splitting a string into parts [closed]

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 would like to split a string in C# for example:
120530
so it will be like this:
Day: 12
Time: 0530
But it will be without spaces, just as it is 120530
How can I do that?
I'm assuming that you know that it will always be 6 digits with the first 2 being day and last 4 being time.
Utilize the Substring() method of your string object...
string allTogether = "120530";
string day = allTogether.Substring(0, 2);
string time = allTogether.Substring(2);
var dayAndTime = "120530";
var day = dayAndTime.Substring(0, 2);
var time = dayAndTime.Substring(2, 4);

Categories