|
|
how to create Const Member methods inside a class. how to create const objects of a Class.
Class Base
{
int member1=10;
public void ModifyMember() // I need to make this method Const
{
member1 +=1;
}
}
//In Main
public static void Main()
{
//how to creat cons objects of class Base
}
|
|
|
|
|
Perhaps you mean 'static', not 'constant'?
|
|
|
|
|
Can't really, however, the example below is close and may introduce some concepts that will get you close to your goal.
public static class Program{
private static readonly Foo mFoo;
public static void Main(){
}
static Program(){
mFoo = new Foo(1);
}
}
public class Foo{
public int Value{
get;
private set;
}
public Foo(int value){
Value = value;
}
}
|
|
|
|
|
Thanks.
How do you create a method , which will only be allowed to read the data Members, but can not be allowed to modify the data of the object <accidental modification=""> .
The static method, can still modify the static data members of the class.
|
|
|
|
|
The only static method is Main and it cannot change the value of mFoo since it is read only. Furthermore, the Value property in Foo has a private set property meaning that only the public property is generally accessible.
|
|
|
|
|
Perhaps you can use "get" keywords
public static string yourProperty
{
get { return ....}
}
|
|
|
|
|
There is no such thing as a Const method. Perhaps you're thinking about a Static method?
Also, there is no such thing as a class declared as Const. Again, you're thinking about static??
|
|
|
|
|
Perhaps this is what you wanted..?
public static class Foo
{
public static int AddOne(int Input)
{
return ++Input;
}
}
class Program
{
static void Main(string[] args)
{
Console.WriteLine(Foo.AddOne(1));
Console.Read();
}
}
|
|
|
|
|
I only hear that the static method and const variable
|
|
|
|
|
HI and thank you in advance.
I am developing a windows mobile application and have encountered some serious problems.
First, I was a Visual c++ programmer and in the process of developing my MFC smart device, I realized there is not much offered in c++ to work with database on smart devices. I so badly needed my application to connect to DB ( and all the examples I was getting were in .NET) that i decided to learn .NET,
After a few days, I learnt some c# and developed my application that connected very well to DB as I wanted.
This application was supposed to be installed on windows mobile devices and be used to make sales in the fields ( e.g by beverage distributors who move around with vehicles).
Hurdle number two came when I needed to print a fiscal receipt for a sale posted by my application.
From my hardware vendor, he recomended the a fiscal printer called TSL Mobile BT, which is approved in my country (Kenya) and connects to the devices via blue tooth. I was also told that another company has already made an application that connects with the device from a PDA. So I went online
http://www.tremol.bg/us/en/products/[^]
and downloaded the dll for the gadget. It has a sample C# desktop application.
I added the library (ZFPCOMLib)to my application and when I run the application I got this error.
COM Object with CLSID
'{239FFB-......27AA} cannot be created due to the following error.Class not registered.
I googled on how to register a dll in windows mobile and found a solution as using regsvrce.exe, but after I copied it to the emulator but was unable to launch it ( in desktops we use cmd and type regsvr xx.dll) but i dint know if windows mobile has cmd and how to launch it or even how to open RUN command..
(if you are done laughing, lets continue), then I so another shocking forum and someone said that a dll working on Desktop application would not work on windows mobile ( due to the target processor for the dll), but the hardware vendor told me someone else had been able to hack it.
Now am stranded, having done a whole desktop operation to manage the inventory for the distributor, and the mobile version doing the sales ( but failing to print fiscal receipts as demanded by the client).
Dear programmers,
Please guide me on what to do next.. If this goes through I shall consider a small reward to the person who shall help me crack it ( first).
Note that my problems are two - how to register a dll on smart device emulator and 2 - the main one- how to make my desktop application dll run on the gadgets.. you may check the providers site for more information on the gadget.
|
|
|
|
|
Hi ,
I don't know if this is possible , cause I didn't have windows mobile right now to test this function
But I will try my best to help you
Try to write a simple .NET Application that uses this code
const int REG_SUCCESS = 0x0;
const string ControlPATH = @"c:\WindowsMobile\MyDLL.dll";
[DllImport(ControlPATH)]
public static extern int DllRegisterServer ();
[DllImport(ControlPATH)]
public static extern int DllUnregisterServer ();
I know nothing , I know nothing ...
|
|
|
|
|
Please tell me the code to connect to ftp server over explicit ssl connection in c# .net
|
|
|
|
|
What have you tried so far? Demanding us to give you code is very rude.
I know the language. I've read a book. - _Madmatt
|
|
|
|
|
Not to mention generally ignored, or for those of us in a sporting mood, generally ridiculed.
.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
|
|
|
|
|
|
nice, didn't know you could that ! lmao
|
|
|
|
|
Ive got a question about sending events between functions, i have created a funcion that generates a picture form strings in form and it looks like:
private void generator(object sender, PaintEventArgs e)
{
Font czcionka = new Font("Arial", 12);
SolidBrush pedzel = new SolidBrush(Color.Black);
Bitmap pic = new Bitmap(Convert.ToInt32(docSzerokosc.Text), Convert.ToInt32(docWysokosc.Text));
StringFormat format = new StringFormat();
format.FormatFlags = StringFormatFlags.DirectionRightToLeft;
string[,] formParm = formularzDane(this);
if (formParm.Length != 0)
{
int iloscParm = formParm.GetLength(0);
double pt = 28.3464567;
for (int x = 0; x < iloscParm; x++)
{
string value = formParm[x, 0];
float X = (Convert.ToSingle(Convert.ToDouble(formParm[x, 1]) * pt));
float Y = (Convert.ToSingle(Convert.ToDouble(formParm[x, 2]) * pt));
PointF wspolrzedne = new PointF(X, Y);
e.Graphics.DrawString(value, czcionka, pedzel, wspolrzedne, format);
}
}
}
and next this pictuse is supposed to send to print event
private void drukStrone(object sender, PrintPageEventArgs e)
{
Paint += new PaintEventHandler(this.generator);
}
and finalli it shold be printed using this funcion
public void zatwierdz_dokument_Click(object sender, EventArgs e)
{
PrintDocument printDoc = new PrintDocument();
printDoc.PrintPage += this.drukStrone;
PrintDialog dlgUstawienia = new PrintDialog();
dlgUstawienia.Document = printDoc;
try
{
printDoc.Print();
}
catch (Exception x)
{
MessageBox.Show("Błąd: " + x.Message + " " + x.HelpLink, "Wyjątek");
}
}
But there is aproblem i think drukStrone does not work properly, it works when i copy code from generator to this funcion but it wold be useless having 2 same fucions(generator is generating pic for print preview also), im stuck and need an idea ;o
|
|
|
|
|
Hi,
I remember printing is an adventure the first time around. Yes it is based on the Paint handler, however it also needs a PrintDocument. And you may or may not want to also have a PrintDialog. I suggest you look for some printing articles (here on CodeProject; or on Google in general) based on those keywords. Maybe my best example is in my Sokoban article[^].
|
|
|
|
|
hi all.
i using c#2005.
i running application and show icon in tray taskbar. when i choice "Disable" in menu tray taskbar => closed all form opening, include forms, messagabox, but application not exit.
i have closed forms if form not show message. if form show messagebox, it not closed.
i wish your help.
regards,
aazz
nothing
|
|
|
|
|
Message Closed
modified 23-Nov-14 6:19am.
|
|
|
|
|
for exam: form A -> Form B -> show messagebox.
if message not show, i can closed Form A and B, but message show i not closed form A and B and message.
can we control messagebox ?
nothing
|
|
|
|
|
Message Closed
modified 23-Nov-14 6:19am.
|
|
|
|
|
i think, we need desig Form Messagebox by user control. at the time, we control it.
you agree.
nothing
|
|
|
|
|
Do you have anything in your "disable" menu that minimizes the app if it's in full screen? The way I normally do this, I have to add something on my form_closing event to see if the user is actually minimizing when they hit the x. If they are, I minimize, otherwise I close. You might have something like e.Cancel = true stopping the app from actually shutting down.
|
|
|
|