|
I use the GraphicsPath's drawString method.
and use the Matrix to set the font's ratio of height and width.
...it can do it,but too complex to implement.
is there a simple method to implement it ?
from vevi
|
|
|
|
|
I have a pointer to a struct. In C++ I can allocate and deallocate it but in C#, I can't. Could you give me a solution plz !
|
|
|
|
|
For example I have a struct like this :
public unsafe struct V
{
unsafe public V* backpointer;
};
When I declare :
V n = new V();
n.backpointer = &x
in a loop then the previous value of backpointer changed.
Could you plz help me ?
modified on Sunday, October 5, 2008 9:50 PM
|
|
|
|
|
I think that the garbage collector deallocated the memory. How can we stop it plz ?
|
|
|
|
|
hockymot2008_2009 wrote: I think that the garbage collector deallocated the memory.
No, it didn't, as you never allocated any memory from the heap.
Despite everything, the person most likely to be fooling you next is yourself.
|
|
|
|
|
hockymot2008_2009 wrote: V n = new V();
That doesn't do what you think that it does. As the struct is a value type, you are not allocating memory for an object, you are just creating a struct value. The value is assigned to the struct n, and will overwrite the previous value in the struct.
Is there any reason why you are trying to use structs instead of classes and pointers instead of references?
Despite everything, the person most likely to be fooling you next is yourself.
|
|
|
|
|
Use the fixed[^] keyword. More about unsafe code[^].
By the way, you don't need a second unsafe keyword inside another unsafe. And you don't need a semicolon after a struct or class declaration.
public unsafe struct V
{
public V* backpointer;
}
Eslam Afifi
|
|
|
|
|
In .NET a struct is always a value type, it's not like in C++ where a struct is either a reference type or a value type depending on how it's used.
You should use a class, not a struct.
Despite everything, the person most likely to be fooling you next is yourself.
|
|
|
|
|
Thanks for your replies
|
|
|
|
|
Does anyone know how to use Rijndael managed with the varying blocksizes?
I have some code to encrypt passwords for storage in a table, however, the blocksize is 128. From what I understand, 128, 160, 192, 224, and 256 bit block sizes can be used. But, when I try, I get an error.
I have been unable to find an article to be able to do it this way. Anyone know of any articles that you can point me to or provide a simple example if you already have one?
Revolutionary: Disk drives go round and round.
|
|
|
|
|
Can I know what you've actually tried that hasn't worked? I would imagine, you'd be able to just set the key size, and then set the key accordingly.
|
|
|
|
|
Take a look here[^], it might help.
While (true) { Human.isLearnable = true; }
|
|
|
|
|
Just for testing I found this random class in an example file.
public class Product
{
public Product(string name, int quantityInStock)
{
_name = name;
_quantityInStock = quantityInStock;
}
private string _name;
public string Name
{
get { return _name; }
set { _name = value; }
}
private int _quantityInStock;
public int QuantityInStock
{
get { return _quantityInStock; }
set { _quantityInStock = value; }
}
}
Now, I created a list.
List<Product> products = new List<Product>();
And added some objects.
products.Add(new Product("A", 5));
products.Add(new Product("B", 4));
products.Add(new Product("C", 3));
products.Add(new Product("D", 2));
products.Add(new Product("E", 1));
However, when I tried using products.Sort(), I got an error. This did not surprise me since I didn't expect it to sort properly. However, I saw the other two overloads List<products>.Sort(Comparison<Product> comparison) and List<products>.Sort(IComparer<Product> comparer). I read the MSDN pages but still don't understand how to use these. Can someone provide some help?
Thanks in advance.
P.S. The casing is messed up in the post but don't worry about it
modified on Sunday, October 5, 2008 5:27 PM
|
|
|
|
|
You need to provide your own comparison method for your product class which lets you compare two products in the way you want to. Here's an example:
private static int CompareProducts(Product x, Product y)
{
if (x == null)
{
if (y == null)
{
return 0;
}
else
{
return -1;
}
}
else
{
if (y == null)
{
return 1;
}
else
{
if(x.Name == y.Name)
return x.QuantityInStock.CompareTo(y.QuantityInStock);
else
return x.Name.CompareTo(y.Name);
}
}
}
and then sort them:
producs.Sort(CompareProducts);
regards
modified 12-Sep-18 21:01pm.
|
|
|
|
|
Thanks, so return 1 means the first is greater, return 0 means they're the same, and return -1 means the second is greater?
|
|
|
|
|
That's correct.
modified 12-Sep-18 21:01pm.
|
|
|
|
|
|
If you for example want to sort by product name, you provide a comparison that compares that property for two items:
products.Sort(delegate(Product x, Product y){return string.Compare(x.Name,y.Name);});
Or if you use framework 3.5, you can use a lambda expression:
products.Sort((x, y) => string.Compare(x.Name,y.Name));
Despite everything, the person most likely to be fooling you next is yourself.
|
|
|
|
|
I tried both of those, and it looks like you can only do string comparisons that way. How do you do int, double, etc. without using ToString() ?
"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." - Jason Jystad, 10/26/2001
|
|
|
|
|
John Simmons / outlaw programmer wrote: How do you do int, double, etc. without using ToString()?
Like normal...
list.Sort( (x,y) => x.Int.CompareTo(y.Int))
xacc.ide - now with TabsToSpaces support IronScheme - 1.0 alpha 4a out now (29 May 2008) ((lambda (x) `((lambda (x) ,x) ',x)) '`((lambda (x) ,x) ',x))
|
|
|
|
|
For integer values you can just subtract them:
products.Sort(delegate(Product x, Product y){return x.QuantityInStock - y.QuantityInStock;});
For double values you can use the Math.Sign method to get a suitable integer value from the difference:
products.Sort(delegate(Product x, Product y){return Math.Sign(x.Price - y.Price);});
Despite everything, the person most likely to be fooling you next is yourself.
|
|
|
|
|
After seeing that, I prefer to stick with the tried/true method of writing the various Comparison delegate functions. It's much easier to understand and maintain. When I code, I don't go "clever" nearly as often as I go "maintainable".
"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." - Jason Jystad, 10/26/2001
|
|
|
|
|
hi friends
what is the difference between == and Equals ?
what is the difference between close and dispose ?
how can i use object (object O = C) ? for what uses ? can i get sample ?
what is the uses for SendKey.Send ? can i get sample ?
thank's for any help
|
|
|
|
|
1) It depends on the language. In C++ == refers to the equality of the memory addresses of the two objects, and Equals refers to the equality of the memory address contents. In .NET I believe the two are basically the same.
2) Close allows the .NET garbage collection engine to work on its own. Dispose forces garbage collection of a particular object. Basically memory management. (Dispose usually still gets called eventually in the close method, but behind the scenes)
3) object O=(Object)C
4) SendKeys is a WinAPI command that allows you to emulate keystrokes from the keyboard and send them to the respective application.
Regards,
Thomas Stockwell
Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning.
Visit my Blog
|
|
|
|
|
Thomas Stockwell wrote: In .NET I believe the two are basically the same.
No[^].
Thomas Stockwell wrote: 2) Close allows the .NET garbage collection engine to work on its own. Dispose forces garbage collection of a particular object. Basically memory management. (Dispose usually still gets called eventually in the close method, but behind the scenes)
Dispose is usually used to free unmanaged resources like GDI handles, but it does not force garbage collection of an object.
modified 12-Sep-18 21:01pm.
|
|
|
|