Click here to Skip to main content
15,894,362 members
Everything / Static

Static

static

Great Reads

by Michael Haephrati
A Static Library which can be used for all kinds of database related needs
by c_a_dunlop
Get 10 tips for revitalizing your existing static analysis implementation—no matter what static analysis tool you're using.
by ToughDev
How to build Wireshark 1.12.5 static binaries for CentOS 5
by ASP.NET Community
GridView UtilitiesThe GetColumnIndexByHeaderText method shown below finds the column index inside a GridView control by passing to it a GridView

Latest Articles

by ToughDev
How to build Wireshark 1.12.5 static binaries for CentOS 5
by Michael Haephrati
A Static Library which can be used for all kinds of database related needs
by DotNetLead.com
How to build and deploy Angular application using GitHub and Azure
by Christian Specht
Jekyll dynamic tree menu: show the whole menu at once

All Articles

Sort by Title

Static 

20 Jan 2018 by Member 13634122
class A { private double x1 ,x2; public static void Main() { x1 = 100; Console.WriteLine (x1); } } What I have tried: these are...
20 Jan 2018 by Thomas Daniels
Main cannot access x1 or x2 because they are instance variables: they only exist on instances of a class. Main is a static method, so it's not associated with an instance, so it can't access x1 or x2: it would only be able to access these two variables if they were marked static as well. And...
20 Jan 2018 by OriginalGriff
The static keyword is a special thing in C#, it says that "regardless of how many instances of this class there are, there is only ever one of these" It's like a physical constant in maths: there is one and only one value of Pi - but you can use it in as many equations and calculations as you...
28 May 2017 by The_Unknown_Member
Hi people. I have confusion understanding why when the Main method is static all the other methods must be static too ? Could someone explain that to me ? What I have tried: Asking a question here in CodeProject.com
28 May 2017 by OriginalGriff
They aren't! The main method must be static, because static methods do not need an instance of the class in order to be called - all non static methods require an instance of the class to be created before you can call them. Since the main method is where your application starts, you can't...
28 May 2017 by Paulo Zemek
They don't need to be all static. Yet, the static method doesn't have an object (the this object) while the non-static methods have it. You can very easily do: class Program { static void Main() { var program = new Program(); program.DoSomething(); } void DoSomething() { ...
10 Aug 2017 by willy wonka 2
In Microsoft c# 2008 I have the following code into a Form: using System; using System.Diagnostics; using System.Drawing; using System.IO; using System.Media; using System.Reflection; using System.Runtime.InteropServices; using System.Windows.Forms; namespace ScreenShots { public partial...
10 Aug 2017 by BillWoodruff
The compiler is telling you that it has not completed compiling the Class, and the Method body you try to reference is not available. Create a Constructor for the Class and set the reference to the Method there: public partial class ScreenShotConfigurationForm : Form { private const int...
29 Apr 2013 by pengm
static export error: in test1.dll: xxx.h class AFX_EXT_CLASS CTest1 { static int num; } xxx.cpp int CTest1::num = 0; in a cpp of test2.dll: test2 is dependent test1.dll ... int i = CTest1::num; ... in a cpp of...
29 Apr 2013 by Leo Chapiro
Probably you have to have a declaration in your executable which uses DLL, like this:declspec( __dllimport ) extern int MyClass:: num;If it does not help, then add a static helper function for accessing that variable, for example:AFX_EXT_CLASS class CTest1{ static int...
29 Apr 2013 by JackDingler
The issue is likely that because you have a DLL importing symbols from another DLL, and that all of the symbols are being marked for export as du[DE] explained above.What you need are conditional declarations dependant on each DLL, so that they won't be mistakenly interpreted incorrectly by...
27 Jan 2017 by Umesh AP
Hi All, I had one php class in namespace App\Http\Lib as GISApplication which contains static data members. I want to set & access values of that static data members from different classes outside of namespace. How Can I set & access that values.
11 Oct 2013 by ASP.NET Community
In this article we are seen how to create a custom HTML Editor control to add image button in it.  Create A
1 Aug 2013 by Hend Riad
I have a WebForm that contain a GridView, a textbox and a button. When i press on the button the data of the text box is added to the GridView. This is my code:public partial class MyClass : System.Web.UI.Page{ Static DataTable dt = new DataTable(); DataRow dr; protected void...
1 Aug 2013 by Tadit Dash (ତଡିତ୍ କୁମାର ଦାଶ)
Use Session. Store DataTable in Session and retrieve and modify whenever you want.
1 Aug 2013 by Vinay Mali
Just avoid use of static.you can use for loop for it.
1 Aug 2013 by Harshil_Raval
Hi, Initialize DataTable object again in ispostback condition will solve your problem.protected void Page_Load(object sender, EventArgs e) { if(!IsPostBack) { dt=new DataTable(); // this will make your object null every time you load page. ...
31 Mar 2010 by Deepak Goyal1
Hello,Does anybody know where I can get coding guidelines for ATL COM. I mean best coding practices or static analysis rules.Thanks!
31 Mar 2010 by Eugen Podsypalnikov
A possible beginning[^]... :)
2 Apr 2010 by Alain Rist
You will find lots of interesting and well written code in Bjarke Viksøe's site ATL section[^].cheers,AR
12 Jun 2013 by vijay kakani
Hi Everyone,I'm new to Open CV and present working on my project which needs background separation done with OpenCV.Two days back I configured Open CV with Visual Studio C++ 2010 and worked on small tutorials from this blog http://opencv-srf.blogspot.ie/By I am not sure about how to...
10 Oct 2015 by Member 10772541
Hello Guys,I read below post and confused what is the best way for datacontext creation and consumption ?http://www.foliotek.com/devblog/avoid-static-variables-in-asp-net/[^]I always thought that we should use singleton like below(+locking) private static ModelDataContext...
8 May 2021 by DotNetLead.com
How to build and deploy Angular application using GitHub and Azure
7 May 2023 by ToughDev
How to build Wireshark 1.12.5 static binaries for CentOS 5
18 Apr 2020 by Member 14782009
Im trying to start timer and changing backcolor of button (from static method). I tried this code but it didnt work : What I have tried: Application.OpenForms.OfType().Last().buttonName.BackColor = Color.LimeGreen; //Button Back Color ...
18 Apr 2020 by OriginalGriff
basically, don't use a static method. You need an instance of a form, make the method a member of that form and use the instance that provides. If you are trying to do this from a different form then you shouldn't - you are making that for (or...
27 Mar 2013 by Grant Mc
Could someone please explain briefly how I create a static variable in a static classIn my code below I can create the Document and Element varaibales fine,So how do I create a varaible from a static class that I have created? public static class Settings { public...
27 Mar 2013 by Ian A Davidson
You can't create an instance of a static class. The whole reason it is static is because you don't need to do so, since all properties and methods are static.I suspect you want to make FileInfo non-static (and its properties as well).Regards,Ian.P.S. I would add that the System.IO...
28 Mar 2013 by José Amílcar Casimiro
static (C# Reference)[^]
10 Dec 2018 by TheBigBearNow
Hello everyone, I have a database table to store my receipt info and on my receipt I have a list of products on the receipt. To store a list I read I need to make another table of that list data and to link the receipt and list of my products together I’m supposed to link with receiptid. To...
10 Dec 2018 by RickZeeland
You can also use LINQ, this will take some study but provides a lot of power and flexibility. See example here: Simple LINQ to SQL in C#[^] And here: Querying SQL Server databases using LINQ to SQL[^]
17 Aug 2018 by Sni.DelWoods
Does declaring a method as static affect performace or ram usage in C#? Say I have 50 users of a web page at the same time which create 50 separate instances of the example class below. I would expect that the WorkerStatic is more efficient that Worker - at least for the Independent() method. ...
17 Aug 2018 by OriginalGriff
No. For a method there is no significant performance difference - the code is loaded once only for all instances regardless of whether it is static or instance related. The individual instances do not get a separate copy of the method as it's code, which is read only anyway!
17 Aug 2018 by Jochen Arndt
There is no significant difference in memory usage and peformance between static and non static methods. The only difference is that non static methods have a hidden parameter to the class instance. This results in a few more bytes of code which execution took some time. But it is negligible. ...
24 Aug 2010 by DavidKiryazi
Hi,C# does not support static variables within methods. To do what you are trying to acheive, you should use a member variable with class scope (ie outside the method).Dave
24 Aug 2010 by cppwxwidgets
it is impossible to have a static local variable in c# if you try to do so you will get the following errorError 1 The modifier 'static' is not valid for this item
24 Aug 2010 by cppwxwidgets
Hi alli wanted to ask if it is possible to have a kind of variable in c# that behave like static local variable in c++,I mean I want to have a local variable in a method, that it is assigned (initialize) just the first time the method invoked and after calling the method again and again it...
24 Aug 2010 by DaveyM69
If you don't want it to change after initialization declare it static readonly. If you want to be able to change it later but have it retain the value between instances just mark it static.
24 Aug 2010 by cppwxwidgets
I want it to be local and in local scope we are not allowed to use static keyword at all, isn't it?
24 Aug 2010 by Sauro Viti
What you are talking about is something like this:void SomeFunction(void){ static int sVar = 1; ...}It is possible to do this in C and C++, but it is not possible in C#. Be aware that the C language is not object oriented and the C++ is a multi paradigm language.The C#...
6 May 2010 by Nishant_Mishra
Good Morning,I have written a Web Method which is called by page method through Java script, this web method executes on button click and as it needed to be static i m not able to call the page controls thus i have another non static method to retrieve the value of radio-button. no as web...
6 May 2010 by NiteshMeshram
Hello Gud MrgPlz Improve your question so that i can put better solution...as i understand Put your Web Method in .asmx file and call method from JavaScript in this case you have no need to make a method as Static...also search for how to Web Methods in asp.net using .asmx file...Let...
20 Mar 2011 by Hamza Hananda
using System;public class MyClass { // non-static method. void nonStaticMeth() { Console.WriteLine("Inside nonStaticMeth()"); } /* Can call a non-static method through an object reference from within a static method. */ public static void staticMeth(MyClass ob)...
19 May 2010 by diialer
Hi,i've got a main form. It's an MDI Parent. In this parent i'm opening a second form and and i'm using a class.Looks like this:public partial class Main : Form { Serial serialPort = new Serial();[...] Util childForm = new Util();[...] ...
19 May 2010 by Not Active
You'll need to pass a reference to the Serial class to the child form obviously. :rolleyes: Create a overloaded constructor and pass it in or create a property and set it.
20 May 2010 by diialer
Is it possible, that you give me an example, cuz i can't find any article. May i search with the wrong keywords. :doh:
11 Oct 2013 by ASP.NET Community
Hello friends.I am going to share with you a concept to call server side method from client side using script manager.Step 1 : Put ScriptManager on
11 Oct 2013 by ASP.NET Community
Most of the time when i tried to search for executing server side static page methods using jquery I came across simple example which explained how
10 Apr 2015 by ChrisCreateBoss
In my previous question (Method must have a return type in C# Class[^]) I used that class to make Global Hotkeys. But when I'm trying to use it, I can't get access to the Constants, which is a public static class; An error is shown: The name "Constants does not exist in the current context....
10 Apr 2015 by Sergey Alexandrovich Kryukov
It looks like everything is correct. All you might have missing is correct naming of the constant. (Again, please review my previous answer to the question you referenced, in part of namespaces.)This is how you can use this constant in the most general case, independent from content. It...
10 Apr 2015 by Sergey Alexandrovich Kryukov
ChrisCreateBoss askedHey something more, I don't want to show my app in the taskbar, that's done already, but when I minimize it, a title bar stays in the left bottom corner of the screen, how can I turn to "false" that?Please see my comment to your question in comments to Solution 1.It...
17 Jul 2017 by Alain Leglise
Hi everybody. I'm trying to compile a console program that uses a static library implementing CString. I'm working with Visual Studio 2012 on Windows 10. Here is the code : File TestLib.h #pragma once #include class TestLib { public: TestLib(){}; TestLib(const CString &tst);...
17 Jul 2017 by Jochen Arndt
It would be good to see the full error message to see which function(s) are missing. If you build your app without MFC support, it is not linked with the library that contains the CString support functions. Because you are including atlstr.h, you are not getting compilation errors. But in the...
16 Jun 2016 by Member 3652617
I have a C# program. I'm watching a directory for changes to an xml file, and when the file changes I want to ready the xml and update a rich textbox.It all works when I specify the file. It reads it and populates the RTB fine. But when I add code to try to do it automatically when the files...
17 Jun 2016 by Matt T Heffron
In addition to my comment above about making the OnChanged method not be static, there are other things very wrong with your code. Not the least of which is the abuse of string concatenation! You should use StringBuilder Class (System.Text)[^]:private void readXML(string Filename){ int...
17 Jun 2016 by Sergey Alexandrovich Kryukov
A method should be static if you simply don't need "this", which is the reference to the instance of some class. This "this" is an implicit method which is passed to all instance methods. (This way, "instance method" is antonym to "static method".) You only can call an instance method on some...
21 Apr 2014 by Fazlan85
I am creating multi DB application from Access DB's. Using a Open dialog box I need to update the connection string DB file path for the access DB. This does not work and gives the error: No error message available, result code: DB_SEC_E_AUTH_FAILED(0x80040E4D). But when I declare a string...
21 Apr 2014 by Aravindba
Hi Declare this after u get path in DUP1 DataRow t; j = s.Rows[0]; x = s.Rows[1]; t = s.Rows[2]; DUP1 = j.ItemArray.GetValue(1).ToString(); //here u declare string and create oledbconnection.what u try before u getting valule for DUP1 u...
24 Apr 2014 by Fazlan85
Hi all I solved it.I did something like this..private void Form1_Load(object sender, EventArgs e) {static string dup = @"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + DUP1 + ";Jet OLEDB:Database Password=1010101010 "; OleDbConnection db = new...
11 Dec 2014 by Matthew Menard
I'm new to building console applications that will continue to run in the background (in C#). I used Visual Studio 2010 to produce the template, so it produced:namespace MyNameSpace { class Program { static int Main(string[] args) { } } }The...
11 Dec 2014 by OriginalGriff
No.If you are in a static method, you can only access static variables and methods, unless you create an instance of a non-static class - in which case you can access it's non-static methods and variables via the instance.You can fake it - by creating a static variable which contains an...
11 Dec 2014 by Afzaal Ahmad Zeeshan
In your code, you can easily instantiate the Progam class and create an object. Did you even give it a try? var program = new Program();Second while working with TCP you might consider looking into the System.Net namespace which would provide the basic but good documents about...
11 Dec 2014 by Sergey Alexandrovich Kryukov
Trying to make anything global is really a bad habit. Why?Static methods, though, are very useful, but only use them if they work only with the object passed as parameters, plus (optional) return object, nothing else; it will help you to avoid static variables, which are potentially...
26 Jul 2013 by Paulo Márcio
CRC32 using user-defined literal.
30 Nov 2010 by ToniChen
Does static methods use up the application resources, which will not be released even if the instance of that class is released?And is there any potential risk to static methods if their class will be used in a multi-threading environment?In design wise, when should we use private static...
30 Nov 2010 by Hiren solanki
Let me try to make you clear about that.with static method It would have one and only instance you will access same instance when you call the static method, So it solves the problem of memory consumption.While with instance method method inside every object will have different values...
8 Jan 2022 by Michael Haephrati
A Static Library which can be used for all kinds of database related needs
2 Oct 2013 by kumar_11
#includeusing namespace std;class foo{private: static int count;public: foo() { count++; } int getcount() { return count; }};int foo::count = 0;int main(){ foo f1, f2, f3; cout
3 Oct 2013 by Sergey Alexandrovich Kryukov
This is just the false statement. Of course they are allowed. Why not?!I never heard of C++ version which would not allow such members, it would be against everything. :-)[EDIT]Please read:...
4 Oct 2013 by BillW33
As SA said the definition of static members is allowed. I was able to compile your code and it runs without any errors from the compiler. You should have described to us exactly what error your are seeing, that greatly helps us to provide the answer that you need. BTW, I am using Visual Studio...
2 Oct 2013 by pasztorpisti
C++ allows the initialization of static members inside the class declaration only in case of static const integral values.class CStaticTest{public: void Test() { printf("%s(%d)\n", __FUNCTION__, g_Member); }private: static const int64 g_Member =...
3 Oct 2013 by User 59241
I think your question is badly worded. It appears you wish to know the number of the class instance. You could achieve that by doing this:class foo{private: static int count; const int mycount;public: foo() : mycount(++count) { } const int getcount()...
9 Jan 2013 by Allgaeuer
Hello everyone,i experienced the following very strange behavior/difference in Visual Studio 2003 and 2010:Two seperate projects will be created in VS2003. One of them is build as a MFC extension DLL (named MFC_Extension_DLL) and the other one is build as a MFC DLL (named MFC_USINGDLL)....
10 Jan 2013 by H.Brydon
I'm not following the story quite 100% but it sounds to me that you have something mixed up in the __declspec(dllimport) and __declspec(dllexport) symbols. Make sure that you have these and the macro symbols using them set up correctly.
10 Jan 2013 by Allgaeuer
Ok, i found the solution.See the following links:Visual Studio 2010 not autolinking static libraries from projects that are dependencies as it should be supposed to[^]What does the “Link Library Dependency” linker option actually do in Visual Studio 2010?[^]
15 Jul 2015 by Akhil Mittal
Access modifiers (or access specifiers) are keywords in object-oriented languages that set the accessibility of classes, methods, and other members. Access modifiers are a specific part of programming language syntax used to facilitate the encapsulation of components.
10 Jun 2021 by Dave Kreskowiak
You will use the default "static constructor" only if your class is defined as static. If it's a normal class, like in your example, there is no "static constructor". There is only the default instance constructor unless you define your own...
10 Jun 2021 by Richard MacCutchan
Static Constructors - C# Programming Guide | Microsoft Docs[^]
26 Jun 2012 by Vaibhav_J_Jaiswal
HiCan anybody tell me, that how to change the static control's caption dynamically on the click event of check box without using the click event message. My requirement is as follows:When user select the check box caption becomes shows "Weighted" and after deselect caption becomes...
25 Jun 2012 by Mohibur Rashid
first set SS_NOTIFY style then static control. It will generate WM_COMMAND with STN_CLICKED message which you can process to get proper view read link[^]
26 Jun 2012 by Style-7
Check box will send the message WM_COMMAND. Use function IsDlgButtonChecked for check box and SetWindowText to static control.
12 Mar 2012 by lukeer
Hi experts,I have a bunch of static member fields like shown below. Throughout the application, a FirstEntry should be unique.Now I want to log which one of those is pointed to by "testEntry".The ToString() method inherited from System.Object returns the class name. I need it to return...
12 Mar 2012 by Fredrik Bornander
To see which instance of the static members you're currently executing ToString for requires you to get the value and then see if that is equal to this, something like this might do the trick;public override string ToString(){ FieldInfo[] fields =...
27 Jun 2013 by Jeneesh K. Velayudhan
I have one Initialize() in my class and I am calling a delegate wrapper method from this function as follows (the call back method will call around 20 times in a sec),public Initialize(){ CX_OUTPUT_CALLBACK cb = new CX_OUTPUT_CALLBACK(OutDelegateCb); ...
27 Jun 2013 by Ron Beyer
public Initialize(){ CX_OUTPUT_CALLBACK cb = new CX_OUTPUT_CALLBACK(OutDelegateCb); AureusSDK_Wrapper_VideoCallbackFunSetup.CX_SetOuputCallBack(cb, cnt); GC.KeepAlive(cb);} public static void OutDelegateCb(IntPtr p_aureus_video_output,...
28 Jun 2013 by Jeneesh K. Velayudhan
11 Oct 2013 by ASP.NET Community
First let’s see what the CSV file is:CSV file is a text based file in which data are separated by comma. It can be opened by excel so you can use
11 Oct 2013 by ASP.NET Community
Factory method is "Define an interface for creating an object, but let the subclasses decide which class to instantiate." In simple words we
11 Oct 2013 by ASP.NET Community
GridView UtilitiesThe GetColumnIndexByHeaderText method shown below finds the column index inside a GridView control by passing to it a GridView
9 Aug 2010 by Miladfa
Hi MohanThanks for providing a nice article.I am using your scripts for creating friendly url.Locall Machine is working fine.When I tried using this in two different shared hosting (Godaddy & 1And1)Its not working in both of the servers..GODADDY The page you tried to...
9 Aug 2010 by Christian Graus
Godaddy is crap. Beyond that, don't post your email address on a public forum unless you want a bigger penis and a russian wife, and use the article forum to talk to an article author. it's at the bottom. This is quick questions, a general forum.
25 Dec 2016 by Abhilash.J.A
Hello everyone, I want to pass list items to one class to anther class. I have used static keyword. But now, when the application is running still old variable is there.Actually I have a listview with checkboxes. After checked checkboxes then click a button. Then popup another window...
25 Dec 2016 by Kornfeld Eliyahu Peter
Because you used static variable it will have the same value across all instances (which is probably very bad), so if you add elements form one instance those will be there when you are in an other instance...As told before this probably very bad and for sure not advised...However, if by any...
25 Jan 2016 by johnstda
I've got the following code for a basic 2d point class: public class PointXY : Point2D { private float x, y; public static readonly PointXY ORIGIN = new PointXY(); public PointXY() { } public PointXY(float x, float y) { ...
25 Jan 2016 by Philippe Mori
One way to do it is to derive from an interface with only read-only members. And you change the type of the "constant" to be the type of that interface instead.interface IPointXY{ float X { get; } float Y { get; }}public class PointXY : Point2D, IPointXY { public static...
25 Jan 2016 by BillWoodruff
While Java has a 'Point2D structure, to my knowledge, C# does not. C# has 'Point, and 'PointF. 'PointF is sealed, so you can't inherit from it. However, assuming you want to be able to handle both integer C# Point, and other numeric-Type C# Types, you can do something like this:public class...
25 Jan 2016 by PIEBALDconsult
I use private setters for the properties:public class Point{ public int X { get ; private set ; } public int Y { get ; private set ; } public Point ( int X , int Y ) { this.X = X ; this.Y = Y ; } public Point() : this ( 0 , 0 ){} public...
14 Aug 2018 by Ahmed AE
I have a problem with understanding the following line of code: static_cast(&QButtonGroup::m_buttonGroup) What I have tried: I searched for the static_cast, and understand it, i know that in this code we are trying to convert the object ...
14 Aug 2018 by Richard MacCutchan
static_cast
24 Jun 2015 by Rahul Anand Jha
I read that you cannot instantiate a static class.However here i am instantiating Array List and surprisingly for me C# has no problems.Also each time my main loop runs i am creating a new instance of the class "TryTo" and adding to it an integer value.Since i created a new instance each time of...