我一直在使用以下代码共享数据库变量:
Namespace DataAccessVariables
Public Class Vars
Public Shared s As String
Public Shared con As String = WebConfigurationManager.ConnectionStrings("Dev").ToString()
Public Shared c As New SqlConnection(con)
Public Shared x As New SqlCommand(s, c)
End Class
End Namespace
Run Code Online (Sandbox Code Playgroud)
然后我将其导入我的项目,如下所示:
Imports DataAccessVariables.Vars
Run Code Online (Sandbox Code Playgroud)
当我用FXCop检查网站时,我收到以下消息:
Error, Certainty 90, for StaticHolderTypesShouldNotHaveConstructors
{
Target : DBVars (IntrospectionTargetType)
Resolution : "Remove the public constructors from 'Vars'."
Help : http://msdn2.microsoft.com/library/ms182169(VS.90).aspx (String)
Category : Microsoft.Design (String)
CheckId : CA1053 (String)
RuleFile : Design Rules (String)
Info : "Instances of types that …Run Code Online (Sandbox Code Playgroud) 我在头文件中创建了一个结构,如下所示:
typedef struct
{
GLfloat lgtR, lgtG, lgtB, lgtA;
GLfloat x, y, z;
bool islight;
GLfloat width, height, depth;
GLenum lightn;
particle prt;
int maxprt;
} emitter;
Run Code Online (Sandbox Code Playgroud)
这没有问题.
但是,在那个特定的头文件中,我想声明一个可以在所有函数中使用的全局发射器,它不是主源文件的一部分:
// header.h global declaration
emmiter currentEmit;
GLvoid glSetEmitter(emitter emitter)
{
currentEmit = emitter;
}
Run Code Online (Sandbox Code Playgroud)
但是,当我尝试这个时,我得到了很多"错误C2228:'.variable'的左边必须有class/struct/union,所以我假设它根本没有声明我的结构.
有没有办法在头文件中全局声明该结构,如果是这样,是否还有一种方法可以防止它成为其他.cpp文件的一部分?
我想知道我们是否可以宣布下面的内容.我的要求是使用相同的变量但不同的结构.如果可以做到以下情况,你们可以帮助我吗?请建议是否还有其他选择.
switch(x)
{
case 1:
struct_1 *name = NULL;
break;
case 2:
struct_2 *name = NULL;
break;
case 3:
struct_3 *name = NULL;
break;
default:
}
Run Code Online (Sandbox Code Playgroud)
问候
我需要在C#中声明包含数组的32个字符串数组.把它全部写出来的工作方式与此类似:
string[] row1 = new string[] { "NO.", "DATA BIN", "BIT2", "BIT1", };
string[] row2 = new string[] { "1", DataBin[1], BitLabels[1, 1], BitLabels[0, 1], };
string[] row3 = new string[] { "2", DataBin[2], BitLabels[1, 2], BitLabels[0, 2], };
string[] row4 = new string[] { "3", DataBin[3], BitLabels[1, 3], BitLabels[0, 3], };
Run Code Online (Sandbox Code Playgroud)
但如果我能像这样创建它们会更清洁/更容易:
string[] row1 = new string[] { "NO.", "DATA BIN", "BIT2", "BIT1", };
for (int i = 2; i < 33; i++)
{
string[] row(i) = new string[] …Run Code Online (Sandbox Code Playgroud) 我发现在某些地方变量声明,比如private int* myint ;
我不太确定*这个语法中的字符是什么,有人可以解释为什么这个*字符在变量声明中与数据类型一起使用?
我想创建一个干净的CSS编码,其中为特定属性创建类,例如,".20mleft"类为20px边距 - 应用的html元素.我希望div的宽度为620px,另一个div的宽度为220px.两个div都向左浮动,620px宽度div的右边应该有20px的边距.这两个div都包含在容器类div中.这些是代码.
HTML:
<div class="container">
<div class="8cols fleft 20mright" style="border:1px #333 solid;"><p>This is the Main Content</p></div>
<div class="3cols fleft" style="border:1px #333 solid;"><p>This is theSidebar</p></div>
</div>
Run Code Online (Sandbox Code Playgroud)
我正在使用12列960网格BTW.
CSS:
/** FLOAT OPTIONS **/
.fleft{float:left;}
/** BOX ELEMENTS **/
.container{width:940px; margin:0 auto;}
...
.3cols {width: 220px;}
...
.8cols {width: 620px;}
/** MARGIN OPTIONS **/
...
.20mright{margin-right:20px;}
Run Code Online (Sandbox Code Playgroud)
问题: .fleft类的属性是唯一可以工作的属性..8cols,.3cols和.20mright类的属性无法应用.我检查了Firefox的Inspector,除了.fleft类声明外,我看不到属性.似乎div的宽度由其内部的内容控制.
有关更好的说明,请下载以下图片:
PS忽略上面的标题.这是我的项目,以防你想知道.
请尽快帮助我.非常感谢.
我正在学习阿达并正在使用这本书Rendez-vous with Ada by Naiditch (1995).在页面上385,给出了包含不完整类型声明的包规范文件的示例:
package Restaurant_Linked_List is
subtype Name_Type is String (1..20);
type Restaurant_Record is private;
procedure Add_To_List (New_Entry: in Restaurant_Record);
procedure Get (New_Restaurant: out Restaurant_Record);
procedure Delete_From_List (Target: in Name_Type);
procedure Search_List (Target: in Name_Type);
procedure Output_List;
private
type Ethnicity is (Chinese, Japanese, French, Korean, Mexican, Italian, Jewish, American, German);
subtype Price_Type is Float range 0.0 .. 150.0;
type Restaurant_Record; -- incomplete type declaration
type Restaurant_Pointer is access Restaurant_Record;
type Restaurant_Record is -- …Run Code Online (Sandbox Code Playgroud) 现在,我并不是说我认为这可以接近正确的编码实践(假设它甚至可能); 这个问题源于凌晨2点的错误:假设类定义类似于以下内容:
class myClass
{
public:
void myMethod(const int & name);
}
Run Code Online (Sandbox Code Playgroud)
和定义:
void myClass::myMethod(const int & altName)
{
//manipulate altName
}
Run Code Online (Sandbox Code Playgroud)
请注意,声明和定义的参数都是const int&类型,唯一的区别是变量名称.我知道这不会(在Visual Studio 2012中)抛出编译器错误或警告,但是在运行程序时是否会导致错误?
谢谢!
我无法识别以下Java中的字符串声明的区别.
假设我有两个字符串
String str1="one";
String str2="two";
Run Code Online (Sandbox Code Playgroud)
有什么区别
String str3=new String(str1+str2);
Run Code Online (Sandbox Code Playgroud)
和
String str3=str1+str2;
Run Code Online (Sandbox Code Playgroud)
在上述两个声明中,内容都str3将是onetwo.
假设我创建了一个新字符串
String str4="onetwo";
Run Code Online (Sandbox Code Playgroud)
然后,在上述声明中,
if(str4==str3) {
System.out.println("This is not executed");
}
Run Code Online (Sandbox Code Playgroud)
为什么str3而str4不是指同一个对象?
我目前正在学习C++并试图理解结构的用法.
在C++中.据我所知,如果你想在main()函数之后定义一个函数,你必须事先声明它,就像在这个函数中一样(请告诉我,如果我错了):
#include "stdafx.h"
#include <iostream>
#include <string>
void printText(std::string); // <-- DECLARATION
int main()
{
std::string text = "This text gets printed.";
printText(text);
}
void printText(std::string text)
{
std::cout << text << std::endl;
}
Run Code Online (Sandbox Code Playgroud)
我现在的问题是,是否有办法对结构进行相同的处理.我不想总是在main()函数之前定义一个结构,只是因为我更喜欢它.但是,当我尝试这样做时,我收到一个错误:
//THIS program DOESN'T work.
#include "stdafx.h"
#include <iostream>
#include <string>
struct Products {std::string}; // <-- MY declaration which DOESN'T work
int main()
{
Products products;
products.product = "Apple";
std::cout << products.product << std::endl;
}
struct Products
{
std::string product;
};
Run Code Online (Sandbox Code Playgroud)
当我删除decleration而不是在main函数之前 …