|
A revelation to me Being able to do this saves me the trouble of having the non-generic classes inherit from a generic-typed abstract class that calls 'SetCache<whatever>
«One day it will have to be officially admitted that what we have christened reality is an even greater illusion than the world of dreams.» Salvador Dali
|
|
|
|
|
Indeed
"I didn't mention the bats - he'd see them soon enough" - Hunter S Thompson - RIP
|
|
|
|
|
If you call
SetCache(x);
and "x" is type string then it compiles
SetCache<string>(x);
if "x" is an int then it compiles
SetCache<int>(x);
whatever type "x" is it assumes the type between the angled brackets is that type. The only time you absolutely have to supply the type is when the IDE can't work out itself what the type is. For example if you have
T GetCache<T>(string key)
then the IDE can't workout what "T" should be from the params
GetCache("username");
In the above code there is no way to work out what GetCache returns so you have to explicitly say;
GetCache<string>("username");
|
|
|
|
|
Thanks, this is a revelation to me
«One day it will have to be officially admitted that what we have christened reality is an even greater illusion than the world of dreams.» Salvador Dali
|
|
|
|
|
F-ES Sitecore wrote: then the IDE can't workout ... I think you mean the compiler.
|
|
|
|
|
I initially wrote the compiler but I didn't know if it was the compiler or VS, but thinking about it it's obviously the compiler 
|
|
|
|
|
|
thanks, Richard, it made my day to discover another thing i should have known
«One day it will have to be officially admitted that what we have christened reality is an even greater illusion than the world of dreams.» Salvador Dali
|
|
|
|
|
Thank you, all, for your illuminating responses ! Any further ideas, comments, critiques, would be very appreciated. If you care to address the more theoretical issue of whether this example embodies a design-pattern, I am all ears. Is the facility to "rehydrate" from instances of objects cast to interfaces to the ab origine strongly typed instance a form of factory pattern, or just a hack to enable collections of mixed types in C#'s strongly typed codeaverse >
a message for: @RichardDeeming @HaroldAptroot @jschell
If you have time to consider what this code does in the light of your comments on my April 24th. post and code example: [^] ... does this example meet my stated goal of:Quote: the goal: use interfaces to enable creating a collection of different types of objects: and, then, at run-time, cast back to the generic type without hard-coding specific types.
a. without using 'dynamic
b. without using reflection
c. without cloning/copying (using something like 'Activator.CreateInstance)
«One day it will have to be officially admitted that what we have christened reality is an even greater illusion than the world of dreams.» Salvador Dali
|
|
|
|
|
I'm not sure. How I interpreted your previous post was that you wanted something like this
IBeing<Cat> b3 = (IBeing<Cat>) cache[1];
Or this
Cat hepcat = BeingCache.GetBeing<Cat>(cache[1]);
Except without mentioning Cat (writing IBeing<Cat> or GetBeing<Cat> or even just Cat would be "hard-coding a specific type"), but not IBeing b1 = cache[1] (because it wouldn't allow "interesting uses" of b1 such as accessing b1.IBInstance ). I still don't think that can be done (at least within the constraints given), but maybe that isn't what you meant.
modified 27-Oct-20 7:03am.
|
|
|
|
|
Hi, Harold, thanks for responding !
I'm just groping the elephant in the dark room hoping to become wiser ... with one usable eye, I'm hallway to getting the "blindness" part down
Do you think the run-time "rehydration" from cast-to-interface back to instance is inherently a reflective process ? Perhaps this kind of hocus-pocus is just bootlegging Dynamic >
Perhaps one of our IL gurus like @Richard-MacCutchan or @RichardDeeming can enlighten us on the internal structure of such entities.
cheers, Bill
«One day it will have to be officially admitted that what we have christened reality is an even greater illusion than the world of dreams.» Salvador Dali
modified 27-Oct-20 16:49pm.
|
|
|
|
|
Hi,
I have tried the following code to restrict input to numbers. But, I have used calcEngin library for doing mathematical calculation in that textBox, so I need to allow "()+-*/" characters too.
How can I allow those special characters?
private void textBoxTT_KeyPress(object sender, KeyPressEventArgs e)
{
if (!char.IsDigit(e.KeyChar))
e.Handled = true;
return;
}
|
|
|
|
|
|
Can you please guide me more? I couldn't understand how to solve my issue.
|
|
|
|
|
Look at the other methods to see which one(s) can provide the checks that you need.
|
|
|
|
|
for cases where you must handle entry of groups of characters that do not map to the many
Is---- methods provided by Char, you may need to test if the char is in a specific group of characters:
private string legalChars = "()+-*/";
private void textBox1_KeyPress(object sender, KeyPressEventArgs e)
{
char c = e.KeyChar;
e.Handled = !
(
char.IsDigit(c)
|| legalChars.Contains(c)
);
}
«One day it will have to be officially admitted that what we have christened reality is an even greater illusion than the world of dreams.» Salvador Dali
|
|
|
|
|
At the moment the program will only reveal a letter if the users input matches the specified letter within the iteration.
What I would like to do is reveal a letter despite what iteration the user is on...e.g. if the user inputs "P" on the first iteration I want the program to reveal all the Ps" in happy.
Thanks!
{
string[] secret = { "h", "a", "p", "p", "y" };
string[] hidden = { "_", "_", "_", "_", "_" };
string letter = "";
Console.WriteLine("Welcome to guess a word game");
for (int i = 0; i < secret.Length; i++)
{
Console.WriteLine("Guess a letter: ");
letter = Console.ReadLine();
if (secret[i] == letter)
{
hidden[i] = letter;
}
foreach (string k in hidden)
{
Console.Write(k.ToString());
}
Console.WriteLine();
}
Console.WriteLine();
if(secret == hidden)
{
Console.WriteLine("You have guessed the correct word!");
}
else
{
Console.WriteLine("unfortunately you have not gussed the correct word");
}
Console.ReadLine();
}
}
}
|
|
|
|
|
some suggestions:
1 use Console.ReadKey() to read a single character at a time: [^]
you can convert the result of ReadKey to a Char or String like this:
ConsoleKeyInfo ckey = Console.ReadKey();
char chr = ckey.KeyChar;
string str = chr.ToString(); 2 you will need to use a loop, like a while loop that lets the user nake attempts:
while (true)
{
Console.WriteLine(hidden);
Console.Write("? ");
ckey = Console.ReadKey();
char chr = ckey.KeyChar;
string str = chr.ToString();
if (secret.Contains(chr))
{
for (int i = 0; i < secret.Length; i++)
{
if (secret[i].Equals(chr))
{
}
}
}
Console.WriteLine();
if (hidden == secret || ckey.Key == ConsoleKey.Escape)
{
Console.WriteLine(hidden);
break;
}
} Hint: use a StringBuilder
«One day it will have to be officially admitted that what we have christened reality is an even greater illusion than the world of dreams.» Salvador Dali
|
|
|
|
|
Message Closed
modified 23-Oct-20 5:40am.
|
|
|
|
|
What is your question about scrolling text?
|
|
|
|
|
And?
What does it do that you didn't expect, or not do that you did?
What have you tried to do to find out why?
Are there any error messages, and if so, where and when? What did you do to make them happen?
This is not a good question - we cannot work out from that little what you are trying to do.
Remember that we can't see your screen, access your HDD, or read your mind - we only get exactly what you type to work with.
And to be honest, even for student grade code, that's really very poor quality! Stop using default names for controls, use an enum instead of a string based mode , use a switch instead of if ... else if ... else if ... and think about what you are doing:
if (mode == "SoSa")
{
...
}
else if (mode == "SaSo")
{
...
}
if (mode == "Asagi")
{
...
}
else if(mode == "Yukari")
{
...
} What if it is none of them?
Shouldn't that be
else if (mode == "Asagi")
Don't use the text of a button to determine what it does: use the Tag field instead - it can hold any type so a bool would be more appropriate.
Don't use string literals directly in code anyway: "DUR" and "DEVAM" should be constant values not inline literals, so if they change at a later date to - say - "Dur" and "Devam" they only need changing in one place.
"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!
|
|
|
|
|
Cordial saludo equipo de Programacion.net les escribe Hernán Martínez saludos desde Colombia, agradezco si me pueden colaborar acerca del inconveniente que tengo respecto a la apertura de una página web que tengo desarrollada haciendo uso de los lenguajes de programación C# ASP.Net:
Antes tengo que aclarar que tengo varias paginas de similar desarrollo dentro de mi proyecto en donde hago uso de la función MessageBox.show
Pero al abrir esta pagina mediante un hiperenlace o hipervínculo me muestra el siguiente error:
Error de servidor en la aplicación '/'.
________________________________________
Error de compilación
Descripción: Error durante la compilación de un recurso requerido para dar servicio a esta solicitud. Revise los detalles de error específicos siguientes y modifique el código fuente en consecuencia.
Mensaje de error del compilador: CS0103: The name 'MessageBox' does not exist in the current context
He visto foros en donde aclaran ese inconveniente y las soluciones que me plantean es:
• Que haga lo mismo, pero en Javascript
• Que utilice Alerts en vez de MessageBox
• Que incluya la referencia System.Windows.Forms y que incluya
using System.Windows.Forms;, cosa que he hecho pero que no he tenido éxito.
La idea como es obvia es que me sirva con la función ‘MessageBox’, como me sirve en las otras páginas de mi proyecto.
Muchas gracias por la colaboración que me puedan brindar
|
|
|
|
|
As stated below, this is an English language site. Please translate your messages.
|
|
|
|
|
Here is the Google Translate for the message:
Cordial greeting team of Programacion.net writes hernán Martínez greetings from Colombia, I appreciate if you can help me about the inconvenience I have regarding the opening of a website that I have developed using the programming languages of ASP.Net:
First I have to clarify that I have several pages of similar development within my project where I make use of the MessageBox.show function
But opening this page using a hyperlink or hyperlink shows me the following error:
Server error in application '/'.
________________________________________
Build failed
Description: An error occurred while compiling a resource required to service this request. Review the specific error details below and modify the source code accordingly.
Compiler error message: CS0103: The name 'MessageBox' does not exist in the current context
I have seen forums where they clarify this inconvenience and the solutions they pose to me is:
• Do the same, but in Javascript
• Use Alerts instead of MessageBox
• Include the System.Windows.Forms reference and include
using System.Windows.Forms;, which I have done but have not been successful.
The idea as is obvious is that it serves me with the 'MessageBox' function, as it serves me on the other pages of my project.
Thank you very much for the collaboration you can give me
It looks like the requester is trying to display messages on a web page but is using MessageBox which is not a JavaScript method. He / she says it works on other pages of the project. He / she should look at the other pages in the project and see what they are doing that is different from what is being done on the page he / she is working on.
|
|
|
|
|
This is a common problem where people build on their own systems and it appears to work (client and server on the same platform). But as soon as they deploy it falls over. As that famous scene in Cool Hand Luke has it, "What we have here is a failure to communicate".
|
|
|
|