|
I don't understand your question completely but this may be help
1- C# is case sensitive , mean that double Radius; and public double radius are not same.
2- Properties is not variable, it's a way for set or get a variable , and variable can be different type from it's properties like:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace circle
{
class circle
{
double Radius;
public string radius
{
get
{
return Radius.ToString();
}
set
{
double i = -1;
if (double.TryParse(value, out i))
{
Radius = i;
}
}
}
public string Circumference
{
get
{
return (2 * Math.PI * Radius).ToString("N6");
}
}
}
class MyApp
{
public static void Main()
{
circle myCircle = new circle();
myCircle.radius = Console.ReadLine();
Console.WriteLine("Radius: = {0}", myCircle.radius);
Console.WriteLine("Circumference: = {0}", myCircle.Circumference);
}
}
}
3- Properties is not only for return existing variable, it can do process for calculating or formatting return value like Circumference properties in above code
4- Properties can be readonly like Circumference properties which you can not set a value for it
Hope helps with this ugly sample code
|
|
|
|
|
Thank you for your reply. You helped very much with your example. I am starting to understand it now.
Thanks again
|
|
|
|
|
I have a list of a custom type that contains 2 variables. One is name, the other is count. What is the general idea of what I need to do in order to condense this into a list with no duplicates where the counts of duplicate names are added together?
(eg. A list with 3 carls, 2 carls, 1 eric, 1 alex and 1 eric should condense to 5 carls, 2 ercis, 1 alex)
An example of the class the list would be populated with:
public class Person
{
private string _name;
public string PersonName
{
get {return _name;}
set { _name = value;}
}
private int _count;
public int PersonCount
{
get { return _count; }
set { _count = value; }
}
public Person(string name, int count)
{
_count = count;
_name = name;
}
}
|
|
|
|
|
and is that a problem? There are many ways to do it:
1.
avoid duplicates from the start; that is the cheapest solution. See also (4)
2.
use two nested for loops, and merge entries with identical names (one gets the sum, the other gets removed)
3.
for better performance, you could sort the list on the name (this[^] may help), then do as in (2)
4.
create a new list which never holds any duplicates; the easiest way to do that is by using a Dictionary where name would be the key, and count the value.
You'll have to choose one and work out the details yourself.
|
|
|
|
|
|
You have to click the button twice to get the desired button effect - once to give the application focus, and then once to actually fire the buttonclick event, I assume.
Is there a general approach that's applicable to all (or the vast majority) of controls, so that one click on a button/control suffices to trigger the click event, whether or not the app has focus at the time of the click?
|
|
|
|
|
sherifffruitfly wrote: You have to click the button twice to get the desired button effect - once to give the application focus, and then once to actually fire the buttonclick event, I assume.
I've noticed this in .NET apps (and MS Office apps running on WinXP and above). My MFC 4.2 (VC6) apps (running on all OSs) work as you would expect - clicking a toolbar button activates the window and causes the button's handler code to execute.
You might want to try handling the WM_MOUSEACTIVATE event in your application's top level Form and posting a WM_LBUTTONDOWN to the Control under the mouse (if any).
Good luck!
/ravi
|
|
|
|
|
Assembly assem = Assembly.LoadFrom("pFile");
Type[] types = assem.GetTypes();
string className = types[0].Name; //This row get class name
How can I get class access modifier?
Thanks..
|
|
|
|
|
There is a set of IsXxx properties (e.g. IsPublic) but their mapping onto the C# keywords isn't really clear to me.
|
|
|
|
|
I know, I get public access modifier;
private string GetClassAccessModifier(Type pClass)
{
if (pClass.IsPublic)
return "public ";
}
But how can I get internal and private modifier.
Non exist following properties;
pClass.IsInternal
pClass.IsPrivate
pClass..IsAssembly
|
|
|
|
|
hi
i have 2 form in my program
publis object from form2 for example "Frm_User" that new in load of mainform and have a filed for example "AllowEdit"
i can access to this filed by Frm_User.AllowEdit
but i want to find a way that access "AllowEdit" by know name of this filed in other form
it mean that i want find a way to dynamically access obj of form2 "Frm_User" by Name and then change that field in mainForm
can any one help me
thnx
|
|
|
|
|
Have you tried casting the object?
If the object is different everytime and you can't edit the objects to use an interface with "allowEdit" then maybe you can try using "reflection" methods to get access.
Look up those things then ask for specific help.
|
|
|
|
|
i know with reflection we can access all property and method with the instance of the object
but my problem is i want to create instance of instance of the object from a string that contain name of that object
for example :
i know that object of from2 is "Frm_User" and string whith this code
string temp="Frm_User";
can i access the object of form 2 with temp?and change property and and field of that?
|
|
|
|
|
Have a look at Activator.CreateInstance().
|
|
|
|
|
You can probably, expose AllowEdit through a public property and set it from your code
love2code
|
|
|
|
|
Hi everyone!
I am a new one to DirectX. Now I want to draw a cube on Windows Mobile. The language I used is C#, and I want to use DirectX technology. I had already drawn every surface. These surfaces can be shown individual. But when I write these datas into a buffer altogether for showing all surfaces, only the first surface can be drawn. Other surface dispear. I don't know the reason. I hope someone could be kind to help me. Thx!
There is some white cloud floating on the blue sky. That's the landscape I like.
|
|
|
|
|
hi guys,
I need your help.
let's suppose I have Dual-Core CPU and I need know how to create two threads, each in different processor.
for example:
thread1 runs in 1core
thread2 runs in 2core
when implementing tread1.start(); thread2.start(); they both run some random function lake NumberTest();
Thanks in advance,
renven
|
|
|
|
|
Thread.SetProcessorAffinity()[^]
It appears as if threading in .Net already distributes multiple threads across all available processors/cores, so you don't appear to have to worry about it.
.45 ACP - because shooting twice is just silly ----- "Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997 ----- "The staggering layers of obscenity in your statement make it a work of art on so many levels." - J. Jystad, 2001
modified on Wednesday, December 23, 2009 10:49 AM
|
|
|
|
|
This is surely a better solution than mine!
|
|
|
|
|
Then vote it a good answer.
.45 ACP - because shooting twice is just silly ----- "Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997 ----- "The staggering layers of obscenity in your statement make it a work of art on so many levels." - J. Jystad, 2001
|
|
|
|
|
Wait, re-reading carefully the documentation it seems that it is only for XNA and XBox360. I tried a small test program and the Thread.SetProcessorAffinity does not exist in the standard 3.5 .NET framework. Am I missing something obvious?
|
|
|
|
|
You're right, and I changed my answer.
.45 ACP - because shooting twice is just silly ----- "Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997 ----- "The staggering layers of obscenity in your statement make it a work of art on so many levels." - J. Jystad, 2001
|
|
|
|
|
Sounds more logical too; imagine all applications dividing their affinity over two cores. You'd freak out if your computer has four cores, as two would be consistently ignored
The CPU-affinity can be set by the end-user over the task-manager, if there's a need to do so.
I are Troll
|
|
|
|
|
C# seems not to support the feature you are requiring, you should use some Interop to do it.
This snippet should do the work (I found it here[^], I didn't tested it.
class Program
{
[DllImport("kernel32")]
static extern int GetCurrentThreadId();
static void Main()
{
Thread t = new Thread(
new ThreadStart(DoWork));
t.Start();
t.Join();
}
static void DoWork()
{
foreach(ProcessThread pt in Process.GetCurrentProcess().Threads)
{
int utid = GetCurrentThreadId();
if (utid == pt.Id)
{
pt.ProcessorAffinity = (IntPtr)(1);
Console.WriteLine("Set");
}
}
}
} But why do you want to change the thread affinity? The scheduler should automatically take advantage of both CPU cores.
|
|
|
|
|
Hi,
don't worry about which processor executes which thread; setting processor affinities isn't necessary at all. If you let everything run without "helping" it, Windows will assign threads to processors dynamically (which means a thread once blocked for some reason might continue on another processor), with some retention as to preserve cache efficiency. It is only in very special cases that you could improve on the automatic assignment.
|
|
|
|