|
One option would be to use Thread.Suspend(), but since it's deprecated it would better if you choose from Mutex, Monitor or Semaphore which are available in the System.Threading namespace.
|
|
|
|
|
I have been studying C# for about 4 or 5 months and then thought "Well I'll just write something from scratch. Well I felt like I've been reading a book on "How To Swim" and then when I jumped in the water I just gasped for air! Well anyway I hoping that someone could look at this and tell me how to use the return for the "public bool TrueOrFalse().
Thanks and sorry this is so elementary. I think I would like to write a book some day named a Beginner Beginner for the Basics of C#. Well any way here it is.
using System;
using System.Collections.Generic;
using System.Text;
namespace StartingOver
{
class RunIt
{
public bool TrueOrFalse()
{
int four = 4;
int five = 5;
bool answer;
Console.WriteLine("4 * 5 should equal: {0}", four * five);
four*five
return answer;
}
public void Getyear()
{
Console.WriteLine("What year will you be beginning?");
string year = Console.ReadLine();
Console.Clear();
Console.WriteLine("Starting all over again in {0}\n", year);
}
static void Main(string[] args)
{
RunIt ri = new RunIt();
ri.Getyear();
ri.TrueOrFalse();
}
}
}
|
|
|
|
|
Hi,
Since the function is returning some value, you would need to extract the value to use it. ri.TrueOrFalse() has a value of Type Boolean. Therefore you would need a variable of Type Boolean to save the value ri.TrueOrFalse() is returning.
If you would like to see if ri.TrueOrFalse() is returning True or False, you may simply check it using If Else conditions.
Hope this helps.
Vinay
ComponentOne LLC.
www.componentone.com
|
|
|
|
|
Right you are almost there!! lets just look at the function you are talking about
public bool TrueOrFalse()
{
int four = 4;
int five = 5;
bool answer;
Console.WriteLine("4 * 5 should equal: {0}", four * five);
four*five
return answer;
}
It will always return false as it stands, because you are declaring answer but not setting it, then returning it. By default it will be set to false.
All you need to do is set it, so something like this (this is done freehand so may not compile)
public bool TrueOrFalse()
{
int four = 4;
int five = 5;
bool answer = false;
Console.WriteLine("4 * 5 should equal: {0}", four * five);
if((four*five) == 20)
{
answer=true;
}
return answer;
}
Hope that helps and its what you wanted
|
|
|
|
|
Hello everyone
Ok I have a problem, I am working on a C# project that connects to my MySQL Database via odbc and I have it set up so I enter information password and username to connect to the database on the MainForm (the MainForm is set up for parent / MDI) once a connection has been established I will than select the table I want from the populated combobox, for example I would select contacts, once contacts has been selected it will open a new windows form within the parent form (MainForm).
Once that new MDIChild form is open I want to be able to access the open database connection from my main form, so I can enter information and save it to the database. I have pretty much everything done other than that.
sorry it if this does not make much sense i have been up sense 3AM going through MEPS for the Navy.
Thank you for your time.
|
|
|
|
|
usually I will use global application class that act as session in my application, the global class contains application global variables stored as list (usually i use sorted list). thus this variable can be accessed by other object in application
sample of global class like this
public static class GlobalApplication
{
private static SortedList<string,> globalVars = new SortedList<string,>();
public static void AddGlobalVar(string variableName, object variableValue)
{
if (!globalVars.Keys.Contains(variableName.ToLower())
{
globalVars.Add(variableName.ToLower(), variableValue);
}
public static object GetGlobalVar(string variableName)
{
if (!globalVars.Keys.Contains(variableName.ToLower())
{
return null;
}
return globalVars[variableName.ToLower()];
}
}
}
by use that class u have to add your database connection or other object to store to global variable and access it within your application. i.e
GlobalApplication.AddGlobalVar("database connection", your.database.object)
YourDatabaseObject db = (GlobalApplication.GetGlobalVar("database connection") == null) ? null : (YourDatabaseObject)GlobalApplication.GetGlobalVar("database connection");
hope it helps
dhaim
programming is a hobby that make some money as side effect
|
|
|
|
|
Hi,
Part1)
I have a base class that implements the methods "DoSomething()" and make it virtual
a) Is there anyway I can force the derivated class to override it too
b) I can't make it abstract, because I need something to be done in the base and in the derivated class
c) I also would like to force the programmer to call base.DoSomething() inside it's own method to be sure the base method to be executed too.
Part2)
If I have a log method, that I'd like to be called from inside every method, is there anyway to get all parameters and values from the function where it's been called without having to specify one by one?
Thanks,
Dirso
|
|
|
|
|
Hi,
1)
This is what I would try:
create a non-virtual public or protected method "PseudoVirtual()" that calls two other
methods say "fixd()" and "virtuaal()";
stuff whatever needs to be done anyway in private fixd();
and provide a protected virtual "virtuaal()" which, when overriden, effectively provides
overrides for "PseudoVirtual" while enforcing a call to "fixd()".
2)
I don't think that is possible (unless you write some code that modifies your IL code).
If it can be done, I'm interested!
|
|
|
|
|
Part1)
a) Nope
b) Even with abstract or an interface you can't specify what the method must do
c) No can do
Part2)
Not so much, no
|
|
|
|
|
Thank you both for the answers. It's pretty much as I thought. But you have to agree with me, it would be very interesting if it was possible
Thanks again,
Dirso
|
|
|
|
|
|
That's amazing!!!! I think it'll solve most of my log problems!!!
Thank you sooooooooo much
Dirso
|
|
|
|
|
You are welcome
Giorgi Dalakishvili
#region signature
my articles
#endregion
|
|
|
|
|
I have to pass pixelformat as a parameter when performing lockbits. But for grayscale images, there is only "Format16bppGrayscale." Does this format work with 8 bit grayscale images? If not, how do i use lockbits with 8bit grayscale images?
|
|
|
|
|
No. Use PixelFormat.Format8bppIndexed .
Despite everything, the person most likely to be fooling you next is yourself.
|
|
|
|
|
if its 8-bit then shouldn't the values range from 0-255? I get black pixel as 0 and white as 169. Is this what its supposed to be?
|
|
|
|
|
Hi,
169 is two thirds of 255, as if you started off with an RGB image and
either one component was absent, or something else went terribly wrong in the
color-to-grayscale conversion.
Or did you have an ARGB image (A=alpha=opacity) and take the wrong 3 out of 4 bytes?
|
|
|
|
|
Hmm it must be the website that i downloaded the image from. Im using the Lena picture in grayscale, which i previously downloaded.
I downloaded the color version of lena and converted into grayscale using photoshop. Pixels return intensities properly now. Thank you.
|
|
|
|
|
Are you sure that it actually is a grayscale image, and not an indexed image that had a palette of 170 grayscale colors?
I found one Lena picture in grascale, that is a GIF image with a 215 color palette.
Despite everything, the person most likely to be fooling you next is yourself.
|
|
|
|
|
Hi,
I have a form with a listbox controls that has some items in it.
When i double click a item from the listbox it opens a new form that as the title of the item.
(you will see that on some chat applications)
OK, code for the above is fine.
Now, i don´t want to open new forms with the same title, i want to prevent that.
If a form titled "bob" already exists and i double click "bob" item from the listbox, i want the existing form to be focused not open another form with same title!!!
Can anyone help me here?
how can i count forms, get their titles so that a can achive that
i suspect that i have to create some kind of mdiparent/child forms to do that.
Thanks
|
|
|
|
|
Hi,
you could keep a Dictionary<string,form> that maps titles to Forms, and before opening
a new Form, look for an existing one if any, then act accordingly. You would have to
remove entries when forms get closed then, using the Closed event.
Or use Application.OpenForms and search for a matching title.
|
|
|
|
|
I searched articles in codeproject and i found an anser in mdi.
|
|
|
|
|
Hi,
I am using C# to insert a date value from the DatePicker into a DateTime
filed in mySQL database.. I am using the following syntax:
'" + datePicker.Value + "'
Plz Help.Thanks In Advance.
|
|
|
|
|
If you want the date part only, you should "'" + datePicker.Value.ToString("yyyy-MM-dd") + "'"
to include the time part too "'" + datePicker.Value.ToString("yyyy-MM-dd hh:mm:ss") + "'"
I hope it helps,
Dirso
|
|
|
|
|
use parameters for command, it will be more effective and secure from sql injection
dhaim
programming is a hobby that make some money as side effect
|
|
|
|