I am using the VB text editor and want to do some basics in C#. All I want to do is create a list of verbs and have them randomly pair to another list of adjectives to perform a primitive gamertag generator. I am not having a specific problem other than I need an example of this simple function to help me learn and surprisingly I can't find anything maybe because it's too simple...If this is not a good place to learn can someone point me in the right direction because YouTube did not have what I wanted.
Load your verbs into a collection - an array or list, whichever you want.
Do the same with the adjectives
Then create another collection which takes two indexes into the collections: that stores the "used" tags so you don't repeat. A Dictionary<int, int> should do it. Load it with the gamertags that you've actually issued.
Now, to generate a new tag, pick two indexes at random. Check to see if they are already used together. If they aren't, add them, and you have your tag.
If not, generate two more and try again.
Think of it as if you were doing it with a paper and pencil, and you'll see what I mean.
There are more efficient ways (ensuring you can't generate duplicates instead of checking for them) but they are rather more complicated, particularly for a beginner.
"I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
"Common sense is so rare these days, it should be classified as a super power" - Random T-shirt
AntiTwitter: @DalekDave is now a follower!
I would like the return value to be sent to a view with some HTML formatting that I have set up. I realize this is quite a trivial question...but I am stuck...i can return whole table results to views, but I am looking for one single scalar value and can't seem to figure out the right approach. Any help would be greatly appreciated.
The thing I am not quite wrapping my head around, is typically I have a model framed out to return values in a table...I define the properties etc...those properties I can then walk through with a for loop and @Html.DisplayTextFor() in a table in the view....
With this, I am just looking to return the results of the query. I can't call the function directly from a view..I think my brain is broken at this point...again I know this is a ridiculously simple ask, but for the life of me, I can't google it, can't make it work with existing knowledge, so I am hopefully asking someone for a bit of a kick in the right direction. Do I need a model that defines the result as a property?
Dave, thanks so much for the detailed response! So if my controller has several methods, all returning somethings to view, how should I approach that? Also, I am using a ViewModel because I have multiple models feeding the page. I also have context classes that I use to feed the data as well...
A Razor page can be returned by any number of methods in a controller, so long as every one of those methods understands that that page can only accept one particular type.
If you've got multiple methods that are sending data to a view page, each method is going to need it's own Razor page, each defining what type it's looking for to match the data passed to it.
You're not going to get away with a single Razor page handling all kinds of data types.
Now, if you're trying to get multiple controller methods to all send data to the same page being returned, only one method can send data to the Razor page (view).
To get multiple methods to generate data, the method that returns the View is going to have to call the other methods and get the data returned by each. It can then wrap all those pieces of data in a single class you'll have to write, and assemble all that data into a single instance of this container class, passing it to the View.
Ok, that makes sense. I come from more of a data science background using more functional programming/scripts, and am trying to implement a semi-functional dashboard of sorts with some signalr components. So if I want to return several boxes that display string results, that is doable, but if I also want some graphical output as well, I am barking up the wrong tree?
Also, I don't suppose the container class return View() would look like return View(context.GetValue1, context.GetValue2, etc...)
No, you can only send one model to the view. So you have to create a class that holds all of the data you need to send to the view, even if that data comes from separate methods. You then call each of those methods and populate the instance of the container class.
This may sound silly, but if what you want is just a single image, why write a program to do it? Why not play the video on your PC, count to three, then press the PrintScreen key. After that, use an image processing tool, e.g. MS-Paint, and paste the image in it.