« first day (3417 days earlier)      last day (1514 days later) » 

12:41 AM
Hello !
How do i select a value from a first item and another value from the last item of a collection in linq ?
isn't alt+enter the shortcut to go to the new line in here ? o_O
Paragraph.Words is a list of words with each has some values. If a paragraph has 'n' number of words, I want to select Words[0].Coords.Left and Words[n].Coords.Right
 
mr5
@Sakthivel ctrl+K on Windows/Linux, cmd+K in Mac (I think)
 
ctrl+k is code formatting
 
mr5
ah
shift+enter
 
First line \n Second line
 
mr5
this
is
SPARTA!!!
 
12:52 AM
lol i thought i could cheat, apparently doesnt work
ah yeah shift
enter. Worked
 
mr5
yeah, \n is literally two characters
while the \n inside a compiler is a single character
 
yes
How you been @mr5
 
mr5
@Sakthivel store them in a queue, pop the first element then loop through the rest (can be done using popping also)
nothing much. just woke up very early. watched many videos, pick up my dumb bell and now I'm sitting on my laptop
 
int FirstItemLeft = Select First Item from the generic collection , then select the property.
int LastItemRight = Select Last Item from the generic collection , then select the property.
@mr5 is looping necessary ?
@mr5 good way to start a day i guess, some coffee would be good ya
 
mr5
lol
yeah. I'm also drinking coffee now. how bout you bud?
 
12:57 AM
I am working 15 hours everyday for the past 10 days, its fun when nobody's at work. Nice weather, unlimited coffee and food !
 
mr5
@Sakthivel it is. Linq also uses loops isn't it?
@Sakthivel you still at work on Sunday?
 
@mr5 It does, not if i do a collection.Foreach or Any etc.. I know the count. Collection[0].Left, Collection[collection[count]).Last ?
@mr5 Everyday ! If i get this done, my name's going down in the patent xD
That'll help me get H1b and move to states. also with a good job
 
mr5
@Sakthivel oh I thought you said, "first and the rest of the element"
 
Only two values. one value from the first item and the other from the last item
 
mr5
@Sakthivel applying for a patent?
 
1:01 AM
@mr5 my company is, yes.
 
mr5
12 mins ago, by Sakthivel
Paragraph.Words is a list of words with each has some values. If a paragraph has 'n' number of words, I want to select Words[0].Coords.Left and Words[n].Coords.Right
you put Words[n] here
oh. H1B is a visa
never heard of that.
I guess I should also start investing knowledge to apply in US hmm
 
:48661747 This is what i am doing
int left = para.Words[0].Coords.Item1;
int right = para.Words[count-1].Coords.Item3;
@mr5 H1B is a work visa to live and work in the US yeah
 
mr5
I wish Chrome just take out the "force dark mode" and put it as a setting or something so I could switch back n forth into light and dark mode.
 
there only around 60k visas provided every year and its a lottery. lucky ones get it
 
mr5
para.Words.First().Coords.Item1
para.Words.Last().Coords.Item3
 
1:07 AM
@mr5 I am a dumb bell. see, i didnt see that
 
mr5
Do they need degree when working in US?
lol
 
It's better if you do lol
 
mr5
okay. I'll try my luck with others lol
 
H1B prevailing wage is based on few categories. #1 - If the person applying is a graduate or not. if not, the wage goes down.
prevailing wage has 4 levels. every level that you skip, your eligible wage goes down. Max wage around $40 and min wage around $17
 
 
5 hours later…
6:19 AM
Morning.
 
mr5
o/
 
@mr5 H1B is the work visa that tech workers apply for. It's the visa that tech companies apply for and sponsor for bringing programmers into the US. Though there are other avenues, for instance L1 visas.
 
mr5
How do people chose between xN versus N%. E.g., x2, x3, x4 versus 100%, 200%, 300%
 
Lots of possible nuances.
Context is important. Take, for instance, two different games, both of which have damage, and both of which have damage modifiers. One might use "x2", the other one "+100%". What's the difference? If the mechanics are relatively simply, "x2" is quick and simple to grasp. Double damage!
 
mr5
@AvnerShahar-Kashtan if I don't have any degrees, am I not allowed to have it?
 
6:24 AM
If it's a game with a lot of modifiers and players like tweaking builds, "+100%" might be more what you're looking for, because it merges well with other modifiers and players looking for "I have a total of +279% bonus from various modifiers" will enjoy it more.
@mr5 Dunno, I never applied for one. It might be one of the filters they have because there are so many applicants for each spot.
 
mr5
7:11 AM
@AvnerShahar-Kashtan do you think a 2 year course would work?
 
@mr5 No idea. If there are many university graduates from your area also applying, you'd have to be very convincingly superior to them.
 
mr5
ayt
 
It might be easier to do it incrementally. Either find a company with a local office in your country, work there for at least a year, and apply for an L1 relocation visa to their US headquarters. Or find a country with easier immigration criteria looking for workers - large US firms are really pushing up their Central and Eastern European offices, I'm told.
 
mr5
Hmm our government just recently breaks an old age agreement (VFA) with the US. Idk if that would affect one's visa application
 
There's absolutely no way of telling how the US government will react to anything in recent years.
 
mr5
7:19 AM
well, there's an evidence of discrimination for our nationality there. Their government much prefer Chinese over Filipinos
 
Maybe generally speaking, but with the current administration, I wouldn't be surprised if Duterte says something pro-Trump, Trump tweets something pro-Duterte in response, and suddenly the state department sends out a memo to all visa processors that Filipinos are to be admitted first. *shrug*.
 
 
2 hours later…
8:56 AM
Mornig
 
9:12 AM
hey people
need a little help with LINQ
 
@CaptainObvious shoot
public double GetDistance => GetDistanceM(Latitude, Longitude, Latitude2, Longitude2);
why cant i use OrderBy(x=>x.GetDistance)
The LINQ expression could not be translated.
 
> DateTime ToDateTime(IFormatProvider provider) =>
throw new InvalidCastException("Conversion to a DateTime is not supported.");
I don't understand this piece of code. How can we pass an interface to a method?
IFormatProvider provider is an interface.
But we must pass some objects to a method, not an interface.
The code is from this page
I'm missing some point.
I tried reading up on IFormatProvider, and there is also a similar situation, where an interface is passed to a method, and is used nowhere else in the code
I'll try reading up some more. Too awkawrd to ask on the main site, the question might be too basic.
 
9:33 AM
noo
 
mr5
@markharringson just understand how OrderBy works first
 
mr5
you're asking to group your collection by the value to be returned by GetDistance. And don't get me started with inferred parameter compatibility
No. I wouldn't read that code.
 
how can i do this
 
mr5
Have you ever wrote a SQL with GROUP BY?
 
9:39 AM
Yes
 
mr5
it works the same way in LINQ
.OrderBy(x=>x.GetDistance) roughly translates to "SELECT <> x FROM <> GROUP BY x.GetDistance"
 
@CopperKettle You have to pass something which implements IFormatProvider. Usually you can just use CultureInfo.CurrentCulture and you're golden.
@markharringson I don't really know what the context of your question is so I can't help a huge amount with it
 
RCL
Hi everyone
 
Did you all working in a sunday?
an actually sunday
 
RCL
is it possible in WPF to load multiple page when the Window initializes?
I mean in a Frame e.g. Frame.Content = new Page1() then Frame.Content = new Page2() but all this does is overwrite Page1()
 
9:53 AM
I always work sundays
@RCL Of course it overwrites it. You're setting Frame's content and then replacing it with something else. What are you trying to achieve?
 
RCL
I want to retain Page1() and then Add Page2() without using a button I want to do it when the Window Loads
So I want to add all the pages in the Frame and use the Frame Navigaton UI to navigate between pages
 
RCL
10:11 AM
 
Ohh
Uh I'm not sure it actually keeps them in memory properly. I never really used WPF frames thoush so I'm not sure
 
RCL
Yeh it seems when the windows is already initialize and you use a button click to load a new page it retains the previous page in the memory and then you can navigate between pages but not when initializing.
 
Is iOS development that horrible?!
 
10:30 AM
Who knows, it's iOS
 
Hi folks, does the order of registering services in IServiceCollection matter? Ping me if you respond this question. Thank you!
 
I don't think it does
 
11:21 AM
@CaptainObvious Thank you. It does not matter. OK.
 
11:38 AM
@MoneyOrientedProgrammer it does
in the case of registring a service of the same type for example
in the case of decoration, it does
in the case of composing collections from other collections, it also does
none of which you will probably use
but still
 
12:01 PM
@Wietlol: Thank you very much!
 
12:33 PM
Hey guys, I'm just wondering if there's a reason why one would be better than the other in the following situation:
User inputs a message which they'll be reminded of at a given Date/Time, app saves said message & date/time to a DB/file, which is loaded at app launch to set the proper timers
Or is there an even better way of saving this data between app sessions?
 
12:53 PM
@CaptainObvious Thank you!
 
1:49 PM
@RoelvanUden thanks for being honest. I'll be sure to ask you about any other c# topics that are not clear to me.
@mr5 thanks
16 hours ago, by mr5
@MyWrathAcademia inside the HttpClient.Response.Content.ReadAsAnythingButStreamAsnyc(), there is a serialization loop. In this loop, you can "break" anytime and that's one of the thing how it can get cancelled. The data is stored in NetworkStream (not in memory, not in storage), and is lost once the connection have been cut then it throws an Exception.
 
2:15 PM
@mr5 Do you mean inside this method response.Content.ReadAsByteArrayAsync() that there is a serialization loop? Is a serialization loop simply a for loop that iterates in series? Is it CancellationTokenSource.Cancel() that breaks out of the loop? So I'm guessing the download operation is done in the loop and when you break out of it the download is interrupted, so response.Content.ReadAsByteArrayAsync()still completes execution but returns without a completed download?
What is NetworkStream and what exception does it throw?
 
2:47 PM
@mr5 and anyone else who understands how cancellation tokens work, consider this scenario: Task<int> firstFinishedTask = await Task.WhenAny(downloadTasks) executes and the first completed task is returned which allows the next statement cts.Cancel(); to execute.
CancellationTokenSource.Cancel() sends a cancellation notification to each cancellation token passed to each client.GetAsync(url, ct) in a ProcessURLAsync(url, client, ct) method that is still executing (the first ProcessURLAsync(url, client, ct) to return a Task is excluded because it has already finished executing). An OperationCancelledException is thrown in client.GetAsync(url, ct).
I know that the exception is never rethrown because the remaining tasks are not awaited but my question is does an exception getting thrown in an async method exit the async method immediately or does the async method still complete executing all its statements and returns a value in which the exception is stored, meaning that downloadTasksQuery contains a list of the completed remaining tasks that represents completed downloads?
CancellationTokenSource.Cancel() sends a cancellation notification to each cancellation token passed to each client.GetAsync(url, ct) in a ProcessURLAsync(url, client, ct) method that is still executing (the first ProcessURLAsync(url, client, ct) to return a Task is excluded because it has already finished executing). An OperationCancelledException is thrown in client.GetAsync(url, ct).
I know that the exception is never rethrown because the remaining tasks are not awaited but my question is does an exception getting thrown in an async method exit the async method immediately or does the async method still complete executing all its statements and returns a value in which the exception is stored, meaning that downloadTasksQuery contains a list of the completed remaining tasks that represents completed downloads?
CancellationTokenSource.Cancel() sends a cancellation notification to each cancellation token passed to each client.GetAsync(url, ct) in a ProcessURLAsync(url, client, ct) method that is still executing (the first ProcessURLAsync(url, client, ct) to return a Task is excluded because it has already finished executing). An OperationCancelledException is thrown in client.GetAsync(url, ct).
I read that if an exception is thrown in an async method that returns a Task or `Task<TResult>, the exception is stored in the returned task and is rethrown when the task is awaited.
 
3:24 PM
I also have a question about the following lines of code in this example
``` // ***Create a query that, when executed, returns a collection of tasks.
IEnumerable<Task<int>> downloadTasksQuery =
from url in urlList select ProcessURLAsync(url, client, ct);

// ***Use ToArray to execute the query and start the download tasks.
Task<int>[] downloadTasks = downloadTasksQuery.ToArray(); ```
Why not add each Task returned by ProcessURLAsync(url, client, ct); directly to an array instead of adding them to an intermediateIEnumerable<Task<int>> first? I dont know anything about IEnumerable so I don't understand why it is used here?
 
V.7
3:41 PM
@MyWrathAcademia tldr; short version?
 
mr5
@MyWrathAcademia tl;dr. When you throw an Exception from Task, the Task will also throw if someone awaits to it.
dude
did you just copy pasted your paragraph twice?
@MyWrathAcademia yes. there is a serialization loop. the most "raw" of them all is the "ReadAsStreamAsync()" which lets you handle raw data on your own. But there's also another wrapper which is `<I forgot its name but it has a method of>.Read() and ReadAsync()
@MyWrathAcademia when you put a "collection" to an IEnumerable<T>, the enumeration is deferred until you loop/access through it (.ToArray, .ToList also triggers the loop)
var t = Task.Run(() => {})
asynchronously executes an empty block
aaa
I'm tired
cya
 
4:19 PM
@mr5 sorry I'm in a place with really bad internet connection. I didn't mean to copy paste the same messages twice. Sending the message kept failing and I guess when retrying it sent the same message more than once. I will flag them for a moderator to delete.
 
mr5
@mshwf they think in "procedural" way
you could technically "draw" something over a constructor of any object, or more basically, you could start drawing as soon as the graphics context is initialized.
Well, I think it would also work in Android since it's using OpenGL behind
@MyWrathAcademia it's okay
 
@mr5 I just want to confirm my underdstanding so far is correct. When CancellationTokenSource.Cancel() causes an exception to be thrown inside the HttpClient.GetAsync(url, ct).HttpResponseMessage.Content.ReadAsByteArrayAsync() async method does the following piece of code return an empty byte array (i.e. urlContents)?
 
Is it good in terms of self-study to just sit and read code in C#, trying to understand it? Or is it better to write a lot of simple programs, solving the problems provided in a textbook?
 
```// GetAsync returns a Task<HttpResponseMessage>.
HttpResponseMessage response = await client.GetAsync(url, ct);

// Retrieve the website contents from the HttpResponseMessage.
byte[] urlContents = await response.Content.ReadAsByteArrayAsync();

return urlContents.Length; ```
 
mr5
@MyWrathAcademia no
when you throw, you don't need to retun something
@CopperKettle read and write
you wouldn't have the knowledge to write something if you didn't read first
and this knowledge wouldn't get stuck in your head if you didn't practice it by writing.
why do I feel so philosophic when writing sentences like this.
 
4:41 PM
@mr5 I don't understand. I thought that when an exception is thrown inside the async method HttpClient.GetAsync(url, ct).HttpResponseMessage.Content.ReadAsByteArrayAsync() it still returns a task but the code which performs the download operation is skipped because you break out of the serialization loop (the loop in which the download operation is carried out) in the HttpClient.GetAsync(url, ct).HttpResponseMessage.Content.ReadAsByteArrayAsync() when an exception is thrown?
 
mr5
it doesn't return
it just throws
var t = Task.Run(() => throw new Exception());
now, this will run fine
if you await to it without a try-catch, your app will crash
 
Can you write it without => please?
Sorry I've not learned that kind of expression
 
mr5
() => { }
is a lambda expression for delegates in C#
think of it as an anonymous function call
its return type is void in this case
void NoName() { }
 
In JavaScript an anonymous function is: var doSomething = function(){};
But not sure what an anonymous function call is?
 
mr5
oh no
I forgot to invoke the method NoName thus rendering my definition lacking
 
4:48 PM
So in () =>{ } () is the function call and {}is the function body?
 
mr5
it should be
void NoName(){} NoName();
it JavaScript, a self-executing anonymous function call looks like this:
(function() {})();
 
mr5
@MyWrathAcademia it's not actually a function call but merely a declaration of function
@MyWrathAcademia {} is function body, yes
or method
 
So () => {} is another way to declare a function?
 
mr5
not in all case
it's contextual
var a = () => {}
would not compile
Action a = () => {};
would
 
4:53 PM
So in () => throw new Exception()) the right operand of the => operator is the return value and the left operand is the anoymous function call?
So you are declaring and calling the function at the samde time with () => throw new Exception())?
 
mr5
ugh
if you provide the return value or your method is just a one-liner only, you can skip adding {} in it thus I end up typing () => throw new Exception() instead of () => { throw new Exception(); }
 
Interesting, both forms work right?
 
mr5
yeah
haven't really checked it myself since I haven't done it in a compiler
try it first
before believing to some random dude on the internet
 
It's quite intuitive
() => throw new Exception() is just more terse
() => throw new Exception() is just more terse
@mr5 thank you. I can't believe I've just learned lamda expressions so quickly
@mr5 in:
8 mins ago, by mr5
Action a = () => {};
What is the variable a? Is it the name of the anoymous function or its return value?
 
mr5
it's not anonymous when it has already a name isn't it?
Action is the type
a is the name
= is the assignment
=> is the... uhm, idk its name
{} is the method body
; is the statement separator
 
5:03 PM
So when you use Action a = () => {}; you can call this function using a();?
 
mr5
yeah
 
Amazing
 
mr5
eh?
 
I mean its great that it now makes sense (to me). So far I have avoided code with lamda expressions.
Because it seemed complicated
 
mr5
it's just a syntactical sugar coating
compiler stuffs
Action a = () => {};
Task.Run(a);
Task.Run(() => {});
 
5:10 PM
Anyway, please can we get back to this (i.e. why you say that a Task is not returned if an exception is thrown in HttpClient.GetAsync(url, ct).HttpResponseMessage.Content.ReadAsByteArrayAsync())?
38 mins ago, by MyWrathAcademia
@mr5 I just want to confirm my underdstanding so far is correct. When CancellationTokenSource.Cancel() causes an exception to be thrown inside the HttpClient.GetAsync(url, ct).HttpResponseMessage.Content.ReadAsByteArrayAsync() async method does the following piece of code return an empty byte array (i.e. urlContents)?
 
mr5
@MyWrathAcademia int GiveMeAnInteger() { throw new Exception("No, I will not"); }
it is supposed to return something right, but this time, it doesn't return an int
it just throws an Exception
same goes for the method you've mentioned
 
But there is no return statement so how can it return something?
 
mr5
IT DOES NOT RETURN!
IT THROWS!
test it
are you familiar with goto label?
or jnz, jz in assembly?
 
Sorry no I'm not but I've heard it is used in c++
I will
Does it mean "go to" somewhere (i.e. a line of code) in the code?
 
mr5
yes
jnz, je, jz does the same thing
jump to a certain memory location
 
5:15 PM
I've never heard of:
1 min ago, by mr5
or jnz, jz in assembly?
 
mr5
goto is the higher level language equivalent
I mentioned it just so you know that you are not obliged to return something when the method is asking for one
return is basically another form of goto
so do throw
 
5:35 PM
@mr5 I've tested calling the method int GiveMeAnInteger() { throw new Exception("No, I will not"); return 12;}and the return statement is not even reached, meaning that throwing an exception ends execution of the method in which it is thrown and the entire program.
Even when the exception is thrown inside a loop
@mr5 So why did the microsoft documentation say that if an exception occurs in an async method that returns a Task or Task<TResult>, the exception is stored in the returned task and is rethrown when the task is awaited?
@mr5 update: The microsoft documentation is correct because:
```static void Main()
{
GiveMeAnInteger();

Console.WriteLine("Exception not rethrown");
}

static async Task GiveMeAnInteger()
{

for (var i = 0; i < 100; i++)
{
throw new Exception("No, I will NOT");
Console.WriteLine("Does this print");
}
return;
}```
Exception not rethrown
outputs the following to the terminal:
Since the Task is not awaited and therefore the exception stored in the Task that returns from GiveMeAnIntegeris not rethrown.
Since the Task is not awaited and therefore the exception stored in the Task that returns from GiveMeAnIntegeris not rethrown.
@mr5 The answer to my question:
1 hour ago, by MyWrathAcademia
@mr5 I just want to confirm my underdstanding so far is correct. When CancellationTokenSource.Cancel() causes an exception to be thrown inside the HttpClient.GetAsync(url, ct).HttpResponseMessage.Content.ReadAsByteArrayAsync() async method does the following piece of code return an empty byte array (i.e. urlContents)?
1 hour ago, by MyWrathAcademia
```// GetAsync returns a Task<HttpResponseMessage>.
HttpResponseMessage response = await client.GetAsync(url, ct);

// Retrieve the website contents from the HttpResponseMessage.
byte[] urlContents = await response.Content.ReadAsByteArrayAsync();

return urlContents.Length; ```
Is:
```class Program
{
static void Main()
{
CancellationTokenSource cts = new CancellationTokenSource();

CancellationToken ct = cts.Token;

cts.Cancel();

GiveMeAnInteger(ct);

Console.WriteLine("Exception NOT rethrown");
}

static async Task GiveMeAnInteger(CancellationToken token)
{

for (var i = 0; i < 100; i++)
{
if (token.IsCancellationRequested == true)
{
throw new Exception("No, I will NOT");
};
Console.WriteLine("Does this print");
}
return;
}
}```
Because the output of the above test is:
Exception NOT rethrown
 
6:27 PM
Since Console.WriteLine("Does this print"); in the above test code represents the code which performs the download operation in the HttpClient.GetAsync(url, ct).HttpResponseMessage.Content.ReadAsByteArrayAsync() async method, the output Exception NOT rethrown proves that when CancellationTokenSource.Cancel() sets CancellationTokenSource.Token.IsCancellationRequested to true
And an exception is thrown (any exception but probably the OperationCancelledException since I think that's thrown by GetAsync) the code which performs the download operation in the serialization loop in the HttpClient.GetAsync(url, ct).HttpResponseMessage.Content.ReadAsByteArrayAsync() async method is skipped because the code after the exception is thrown is not reached
But because "if an exception occurs in an async method that returns a Task or Task<TResult>, the exception is stored in the returned task and is rethrown when the task is awaited" therefore the code that performs the download operation is skipped (i.e. not executed) and the async method GiveMeAnInteger still returns a Task so the contents of the website are not downloaded and so the byte[] (i.e. byte array) which stores url contents as bytes is empty.
 
 
1 hour later…
7:29 PM
@mr5 I forgot to ask an important question needed for me to understand what IEnumerable is. What is an Enumeration in the following context? Is it the count of elements in a collection?
4 hours ago, by mr5
@MyWrathAcademia when you put a "collection" to an IEnumerable<T>, the enumeration is deferred until you loop/access through it (.ToArray, .ToList also triggers the loop)
 
 
3 hours later…
10:02 PM
@MyWrathAcademia enumerate is a verb/action: to use the collection: to go over each item.
 
 
2 hours later…
11:36 PM
anybody in here !
 

« first day (3417 days earlier)      last day (1514 days later) »