And if so, why can't you do this:
public interface IParsable
{
static IParsable Parse(string s);
static bool TryParse(string s, out IParsable);
}
in C#?
EDIT: Or, alternatively:
public interface IParseable<T>
{
static T Parse(string s);
static bool TryParse(string s, out T);
}
EDIT #2:
I have learned the folly of m...
Hey all, I've been reading up on the best way to implement the GetHashCode() override for objects in .NET, and most answers I run across involve somehow munging numbers together from members that are numeric types to come up with a method. Problem is, I have an object that uses an alphanumeric string as its key, and I'm wondering if the...
I'm a little fuzzy on what the difference between a "group" and a "capture" are when it comes to .NET's regular expression language. Consider the following C# code:
MatchCollection matches = Regex.Matches("{Q}", @"^\{([A-Z])\}$");
I expect this to result in a single capture for the letter 'Q', but if I print the properties of the ret...
I have a form, myForm, which has KeyPreview set to true.
The idea is that I want to capture CTRL-Enter and fire the submit button of the form, no matter what textbox (or other control) that may have focus.
So I set up this method:
private void myForm_KeyUp(object sender, KeyEventArgs e)
{
if (e.Control && e.KeyCode == Keys.Enter)
...
Hi ..
I want to ask about the files that are found in the folder of a simple C# Project .
like
(.pdb file , .vshost file , .manifest file ) in bin folder
( .csproj.fileListAbsolute.txt file , .pdb file ) in debug folder
(AssemblyInfo.cs ) in Properties folder
what is the function of each file of them ?
and which of them is i...
I am looking for an implementation similar to that of what is seen on banking sites. If a user comes to the site I want them to have to pass some form of registration IE (answer a question or enter in some key). If the user closes the browser and comes back to the site again from that machine they would just be able to provide login cr...
I am working on some documentation and need to reference the .Net Framework Class Library. Does anyone know the best way to do this? I was thinking something like the following:
.Net Framework Class Library,
http://msdn.microsoft.com/en-us/library/ms229335.aspx
Wasn't sure if I should include a date or something. I couldn't find ...
I'd like to use a HashSet in a powershell script. I think I've figured out how to instantiate generic collection objects by doing:
[type] $strType = "string"
$listClass = [System.Collections.Generic.List``1]
$listObject = $base.MakeGenericType(@($t))
$myList = New-Object $setObject
This works fine for lists and dictionaries, but when ...
While struggling with DateTime.ParseExact formatting issues, I decided to feed ParseExact the out put from DateTime.ToString(), like this:
DateTime date2 = new DateTime(1962, 1, 27);
string[] expectedFormats = { "G", "g", "f", "F", "D", "d", "M/d/yyy", "MM/dd/yyy", "MM-dd-yyy", "MMM dd, yyy", "MMM dd yyy", "MMMM dd, yyy", "MMMM dd yyy" ...
I have some concern about designing Datasets.
I was told that it would be good to have a dataset for each table for maintenance purpose. Because frequent change in database tables is expected, having one dataset including every tables would be pain to make the corresponding change in the application.
Q. is it good approach to have a ...
I have this code for an ownerdrawn list box that is repainting too frequently. It seems to be related to trying to scroll an event with a different height than normal.
Here is the 'smallest code to reproduce the problem' that can be pasted into a blank form (erase the designer file) - VB version (c# of course does the same thing):
Publ...
I am not the programmer, I dont have access to the Code Behind.
I just style the pages and whatnot.
PROBLEM: I am trying to hide/show elements of a page based on the language selected.
Some of these elements are server controls and a couple of them have specific id's and graphics associated.
I need to change the graphics to the lang...
I'm using .NET Connector to connect to MySQL.
In my application there are few threads using the same connection, so if a MySQLDataReader is not closed yet and some thread is trying execute a query it gives that error:
There is already an open DataReader associated with this Connection which must be closed first.
Will there ever be ...
I have a .NET web service that is trying to log to the Windows Event Log. However, when I try to send a SOAP request to a web method in this web service, I get back this error in the SOAP response:
System.InvalidOperationException: Cannot open log for source 'MySource'. You may not have write access. ---> System.ComponentModel.Win32...
The page that I'm currently working on searches for various entities based on what portfolio they are in. In order to apply the other search criteria (besides for Portfolio) the page first gets the entities by portfolio and then applies the criteria to them, as shown here:
IPortfolioLogic logic = this.objectFactory.GetObject<IPortfolioL...
I have the following code:
public partial class Form1 : Form
{
public BindingList<Class> List = new BindingList<Class>();
public Form1()
{
InitializeComponent();
List.Add(new Class());
comboBox1.DataSource = List;
}
}
public class Class : Dictionary<string, string>
{
public override string T...
Is there any way to perform private key encryption in C#?
I know about the standard RSACryptoServiceProvider in System.Security.Cryptography, but these classes provide only public key encryption and private key decryption. Also, they provide digital signature functionality, which uses internally private key encryption, but there are not...
I'm trying to wrap my head around asynchronous calling of methods.
public IDictionary<string, int> DoSomething(string startsWith)
{
return new Dictionary<string, int>();
}
public IAsyncResult BeginDoSomething(string startsWith, AsyncCallback callback,
object state)
{
return new Func<string, ...
I'm currently using SMO to help automate the patching and/or upgrading of customer databases that are in production. I'm using the following code
Public Sub RunScript(ByVal db As Database, ByVal scriptInfo As FileInfo)
If scriptInfo.Exists Then
RaiseEvent LogMessage("Executing Indicated Script: " & scriptInfo.Name)
...
I have to write several small vertical gradients (on a loop) and so I think it's faster to re-use an existing LinearGradientBrush (correct?)
But this isn't what I expected to happen...
Drawing2D.LinearGradientBrush myBrush = new Drawing2D.LinearGradientBrush(new Rectangle(0, 0, 200, 200), Color.Red, Color.Black, Drawing2D.LinearGradi...